Skip to content

Commit

Permalink
Add error handling for report duplication
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab committed Jan 9, 2025
1 parent c514f2d commit fb7ba4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/org/gridsuite/report/server/ReportController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import org.gridsuite.report.server.dto.Report;
import org.gridsuite.report.server.dto.ReportLog;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -87,9 +89,16 @@ public void createReport(@PathVariable("id") UUID id, @RequestBody ReportNode re

@PostMapping(value = "reports/{id}/duplicate", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Duplicate a report")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The report has been duplicated")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "The report has been duplicated"),
@ApiResponse(responseCode = "404", description = "Report not found")
})
public ResponseEntity<UUID> duplicateReport(@PathVariable("id") UUID id) {
return ResponseEntity.ok(service.duplicateReport(id));
try {
return ResponseEntity.ok(service.duplicateReport(id));
} catch (NoSuchElementException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
}

@DeleteMapping(value = "reports/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ public void testDuplicateReport() throws Exception {
assertReportsAreEqualIgnoringIds(resultAfterDuplication, toString(EXPECTED_REPORT_ONE));
}

@Test
public void testDuplicateReportNotFound() throws Exception {
mvc.perform(post(URL_TEMPLATE + "/reports/" + REPORT_UUID + "/duplicate")
.contentType(APPLICATION_JSON))
.andExpect(status().isNotFound());
}

@Test
public void testDeleteReport() throws Exception {
String testReport1 = toString(REPORT_ONE);
Expand Down

0 comments on commit fb7ba4b

Please sign in to comment.