Skip to content

Commit 0a6a5fa

Browse files
author
LE SAULNIER Kevin
committed
fix: delete study layout on study deletion
Signed-off-by: LE SAULNIER Kevin <[email protected]>
1 parent e7ebe25 commit 0a6a5fa

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/main/java/org/gridsuite/studyconfig/server/controller/StudyLayoutController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,13 @@ public ResponseEntity<StudyLayout> getStudyLayout(
4646
@PathVariable("id") UUID studyLayoutUuid) {
4747
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyLayoutService.getByStudyLayoutUuid(studyLayoutUuid));
4848
}
49+
50+
@DeleteMapping(value = "/{id}")
51+
@Operation(summary = "Delete study layout")
52+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The study layout is deleted")})
53+
public ResponseEntity<StudyLayout> deleteStudyLayout(
54+
@PathVariable("id") UUID studyLayoutUuid) {
55+
studyLayoutService.deleteStudyLayout(studyLayoutUuid);
56+
return ResponseEntity.ok().build();
57+
}
4958
}

src/main/java/org/gridsuite/studyconfig/server/service/StudyLayoutService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public StudyLayout getByStudyLayoutUuid(UUID studyLayoutUuid) {
2626
.toDto();
2727
}
2828

29+
@Transactional
30+
public void deleteStudyLayout(UUID studyLayoutUuid) {
31+
studyLayoutRepository.deleteById(studyLayoutUuid);
32+
}
33+
2934
@Transactional
3035
public UUID saveStudyLayout(StudyLayout studyLayout) {
3136
StudyLayoutEntity studyLayoutEntity = studyLayoutRepository.save(studyLayout.toEntity());

src/test/java/org/gridsuite/studyconfig/server/StudyLayoutControllerTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import java.util.Map;
2323
import java.util.UUID;
2424

25-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
26-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
27-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
2828
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2929
import static org.assertj.core.api.Assertions.assertThat;
3030

@@ -52,6 +52,15 @@ void testGetStudyLayout() throws Exception {
5252
assertThat(result).usingRecursiveComparison().isEqualTo(expectedResult.toDto());
5353
}
5454

55+
@Test
56+
void testDeleteStudyLayout() throws Exception {
57+
StudyLayoutEntity expectedResult = studyLayoutRepository.save(createStudyLayout().toEntity());
58+
mockMvc.perform(delete("/v1/study-layout/{studyLayoutUuid}", expectedResult.getUuid()))
59+
.andExpect(status().isOk());
60+
61+
assertTrue(studyLayoutRepository.findById(expectedResult.getUuid()).isEmpty());
62+
}
63+
5564
@Test
5665
void testSaveStudyLayout() throws Exception {
5766
StudyLayout studyLayoutToSave = createStudyLayout();

0 commit comments

Comments
 (0)