Skip to content

Commit

Permalink
[#82] Add Doc to ComponentController
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Aug 22, 2024
1 parent 340420a commit dab6ee6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Component> 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) {
Expand All @@ -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) {
Expand All @@ -59,20 +80,37 @@ 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<Function> getFunctions(@PathVariable(name = "componentFragment") String componentFragment) {
log.info("> getFunctions - {}", componentFragment);
URI componentUri = identifierService.composeIdentifier(Vocabulary.s_c_component, componentFragment);
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<FailureMode> getFailureModes(@PathVariable(name = "componentFragment") String componentFragment) {
log.info("> getFailureModes - {}", componentFragment);
URI componentUri = identifierService.composeIdentifier(Vocabulary.s_c_component, 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) {
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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){
Expand Down

0 comments on commit dab6ee6

Please sign in to comment.