From e2254c2942702e68621b81670460c5e02b38ab6c Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 22 Aug 2024 12:52:45 +0200 Subject: [PATCH] [#82] Add Doc to ComponentController --- build.gradle | 2 + .../controller/ComponentController.java | 74 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/build.gradle b/build.gradle index a90dce9..c7e7ca3 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,8 @@ dependencies { implementation 'com.fasterxml:classmate:1.5.0' implementation 'com.opencsv:opencsv:5.3' + implementation 'io.swagger.core.v3:swagger-annotations:2.2.22' + implementation 'org.projectlombok:lombok:1.18.30' annotationProcessor 'org.projectlombok:lombok:1.18.30' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/ComponentController.java b/src/main/java/cz/cvut/kbss/analysis/controller/ComponentController.java index 15156b6..df3d377 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/ComponentController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/ComponentController.java @@ -9,6 +9,9 @@ import cz.cvut.kbss.analysis.service.IdentifierService; import cz.cvut.kbss.analysis.util.Vocabulary; import cz.cvut.kbss.jsonld.JsonLd; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -31,11 +34,20 @@ public class ComponentController { private final ComponentRepositoryService repositoryService; private final IdentifierService identifierService; + @Operation(summary = "Retrieve all components") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Successfully retrieved all components") + }) @GetMapping(produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}) public List findAll() { return repositoryService.findAll(); } + + @Operation(summary = "Create a new component") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "Component created successfully"), + }) @ResponseStatus(HttpStatus.CREATED) @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}) public Component create(@RequestBody Component component) { @@ -44,12 +56,21 @@ public Component create(@RequestBody Component component) { return component; } + @Operation(summary = "Update an existing component") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Component updated successfully"), + }) @PutMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}, produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}) public Component update(@RequestBody ComponentUpdateDTO componentUpdate) { log.info("> update - {}", componentUpdate); return repositoryService.updateByDTO(componentUpdate); } + @Operation(summary = "Delete a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "Component deleted successfully"), + @ApiResponse(responseCode = "404", description = "Component not found") + }) @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping(value = "/{componentFragment}") public void delete(@PathVariable(name = "componentFragment") String componentFragment) { @@ -59,6 +80,11 @@ public void delete(@PathVariable(name = "componentFragment") String componentFra repositoryService.remove(componentUri); } + @Operation(summary = "Retrieve functions of a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Functions retrieved successfully"), + @ApiResponse(responseCode = "404", description = "Component not found") + }) @GetMapping(value = "/{componentFragment}/functions", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}) public Set getFunctions(@PathVariable(name = "componentFragment") String componentFragment) { log.info("> getFunctions - {}", componentFragment); @@ -66,6 +92,11 @@ public Set getFunctions(@PathVariable(name = "componentFragment") Stri return repositoryService.getFunctions(componentUri); } + @Operation(summary = "Retrieve failure modes of a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Failure modes retrieved successfully"), + @ApiResponse(responseCode = "404", description = "Component not found") + }) @GetMapping(value = "/{componentFragment}/failureModes", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}) public Set getFailureModes(@PathVariable(name = "componentFragment") String componentFragment) { log.info("> getFailureModes - {}", componentFragment); @@ -73,6 +104,13 @@ public Set getFailureModes(@PathVariable(name = "componentFragment" return repositoryService.getFailureModes(componentUri); } + + @Operation(summary = "Add a failure mode to a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "Failure mode added successfully"), + @ApiResponse(responseCode = "400", description = "Invalid input"), + @ApiResponse(responseCode = "404", description = "Component not found") + }) @ResponseStatus(HttpStatus.CREATED) @PostMapping(value = "/{componentFragment}/failureModes", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}) public FailureMode addFailureMode(@PathVariable(name = "componentFragment") String componentFragment, @RequestBody FailureMode failureMode) { @@ -82,6 +120,11 @@ public FailureMode addFailureMode(@PathVariable(name = "componentFragment") Stri return repositoryService.addFailureMode(componentUri,failureMode); } + @Operation(summary = "Add a failure mode by URI to a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "Failure mode added by URI successfully"), + @ApiResponse(responseCode = "404", description = "Component or failure mode not found") + }) @ResponseStatus(HttpStatus.CREATED) @PostMapping(value = "/{componentFragment}/failureModes/{failureModeFragment}", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}) public void addFailureModeByURI(@PathVariable(name = "componentFragment") String componentFragment, @PathVariable(name = "failureModeFragment") String failureModeFragment) { @@ -91,6 +134,11 @@ public void addFailureModeByURI(@PathVariable(name = "componentFragment") String repositoryService.addFailureModeByUri(componentUri, failureModeUri); } + @Operation(summary = "Delete a failure mode from a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "Failure mode deleted successfully"), + @ApiResponse(responseCode = "404", description = "Component or failure mode not found") + }) @DeleteMapping(value = "/{componentFragment}/failureModes/{failureModeFragment}") public void deleteFailureMode(@PathVariable(name = "componentFragment") String componentFragment, @PathVariable(name = "failureModeFragment") String failureModeFragment) { log.info("> deleteFailureMode - {}, {}", componentFragment, failureModeFragment); @@ -101,6 +149,12 @@ public void deleteFailureMode(@PathVariable(name = "componentFragment") String c log.info("< deleteFailureMode"); } + @Operation(summary = "Add a function to a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "Function added successfully"), + @ApiResponse(responseCode = "400", description = "Invalid input"), + @ApiResponse(responseCode = "404", description = "Component not found") + }) @ResponseStatus(HttpStatus.CREATED) @PostMapping(value = "/{componentFragment}/functions", consumes = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE}) public Function addFunction(@PathVariable(name = "componentFragment") String componentFragment, @RequestBody Function function) { @@ -120,6 +174,11 @@ public Function addFunctionByURI(@PathVariable(name = "componentFragment") Strin return repositoryService.addFunctionByURI(componentUri, functionUri); } + @Operation(summary = "Add a function by URI to a component") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "Function added by URI successfully"), + @ApiResponse(responseCode = "404", description = "Component or function not found") + }) @DeleteMapping(value = "/{componentFragment}/functions/{functionFragment}") public void deleteFunction(@PathVariable(name = "componentFragment") String componentFragment, @PathVariable(name = "functionFragment") String functionFragment) { log.info("> deleteFunction - {}, {}", componentFragment, functionFragment); @@ -130,6 +189,11 @@ public void deleteFunction(@PathVariable(name = "componentFragment") String comp log.info("< deleteFunction"); } + @Operation(summary = "Link two components") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Components linked successfully"), + @ApiResponse(responseCode = "404", description = "Component not found") + }) @PostMapping(value = "/{componentFragment}/linkComponent/{linkFragment}") public Component linkComponents( @PathVariable(name = "componentFragment") String componentFragment, @@ -141,6 +205,11 @@ public Component linkComponents( return repositoryService.linkComponents(componentUri, linkComponentUri); } + @Operation(summary = "Unlink a component from its linked components") + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "Component unlinked successfully"), + @ApiResponse(responseCode = "404", description = "Component not found") + }) @DeleteMapping(value = "/{componentFragment}/linkComponent") public void unlinkComponents(@PathVariable(name = "componentFragment") String componentFragment) { log.info("> unlinkComponents - {}", componentFragment); @@ -150,6 +219,11 @@ public void unlinkComponents(@PathVariable(name = "componentFragment") String co log.info("< unlinkComponents"); } + @Operation(summary = "Merge two components into one") + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "Components merged successfully"), + @ApiResponse(responseCode = "404", description = "One or both components not found") + }) @PostMapping(value = "/mergeComponents/{sourceFragment}/{targetFragment}") public void mergeComponents(@PathVariable(name = "sourceFragment") String sourceFragment ,@PathVariable(name = "targetFragment") String targetFragment){