diff --git a/src/main/java/com/isaacandrade/blog/controller/TechnologyController.java b/src/main/java/com/isaacandrade/blog/controller/TechnologyController.java index 43221f1..463acf2 100644 --- a/src/main/java/com/isaacandrade/blog/controller/TechnologyController.java +++ b/src/main/java/com/isaacandrade/blog/controller/TechnologyController.java @@ -41,7 +41,7 @@ public class TechnologyController { tags = {"Tecnologias"}, responses = { @ApiResponse(description = "Success", responseCode = "200", - content = @Content(schema = @Schema(implementation = Technology.class)) + content = @Content(schema = @Schema(implementation = CreateTechnologyDto.class)) ), @ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), @ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), @@ -54,30 +54,6 @@ public ResponseEntity createTechnology(@RequestBody CreateTechnol return ResponseEntity.status(HttpStatus.CREATED).body(createdTechnology); } - // Endpoint para obter uma tecnologia pelo ID - @GetMapping( - value = "/{id}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML} - ) - @Operation(summary = "Encontre a Tecnologia pelo Id", description = "Encontre a Tecnologia pelo Id", - tags = {"Tecnologias"}, - responses = { - @ApiResponse(description = "Success", responseCode = "200", - content = @Content(schema = @Schema(implementation = Technology.class)) - ), - @ApiResponse(description = "No Content", responseCode = "204", content = @Content), - @ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), - @ApiResponse(description = "Unautorized", responseCode = "401", content = @Content), - @ApiResponse(description = "Not Found", responseCode = "404", content = @Content), - @ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), - } - ) - public ResponseEntity getTechnologyById(@PathVariable Long id) { - Optional technology = technologyService.getTechnologyById(id); - return technology.map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build()); - } - // Endpoint para listar todas as tecnologias @GetMapping( produces = {MediaType.APPLICATION_JSON, @@ -94,7 +70,7 @@ public ResponseEntity getTechnologyById(@PathVariable Long id) { responseCode = "200", content = @Content( mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = Technology.class)) + array = @ArraySchema(schema = @Schema(implementation = TechnologyDto.class)) ) ), @ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), @@ -103,8 +79,10 @@ public ResponseEntity getTechnologyById(@PathVariable Long id) { @ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), } ) - public ResponseEntity> getAllTechnologies() { - List technologies = technologyService.getAllTechnologies(); + public ResponseEntity getAllTechnologies() { + + TechnologyDto technologies = technologyService.getAllTechnologies(); + return ResponseEntity.ok(technologies); } @@ -114,7 +92,7 @@ public ResponseEntity> getAllTechnologies() { tags = {"Tecnologias"}, responses = { @ApiResponse(description = "Success", responseCode = "200", - content = @Content(schema = @Schema(implementation = Technology.class)) + content = @Content(schema = @Schema(implementation = TechnologyDto.class)) ), @ApiResponse(description = "No Content", responseCode = "204", content = @Content), @ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), @@ -123,9 +101,11 @@ public ResponseEntity> getAllTechnologies() { @ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), } ) - public ResponseEntity> getTechnologyByType(@PathVariable String type) { + public ResponseEntity getTechnologyByType(@PathVariable String type) { + TechnologyType technologyType = TechnologyType.valueOf(type.toUpperCase()); - List technologies = technologyService.getTechnologyByType(technologyType); + TechnologyDto technologies = technologyService.getTechnologyByType(technologyType); + return ResponseEntity.ok(technologies); } @@ -142,7 +122,7 @@ public ResponseEntity> getTechnologyByType(@PathVariable String tags = {"Tecnologias"}, responses = { @ApiResponse(description = "Updated", responseCode = "200", - content = @Content(schema = @Schema(implementation = Technology.class)) + content = @Content(schema = @Schema(implementation = TechnologyDto.class)) ), @ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), @ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), diff --git a/src/main/java/com/isaacandrade/blog/service/TechnologyService.java b/src/main/java/com/isaacandrade/blog/service/TechnologyService.java index ab48cc7..d43e66e 100644 --- a/src/main/java/com/isaacandrade/blog/service/TechnologyService.java +++ b/src/main/java/com/isaacandrade/blog/service/TechnologyService.java @@ -1,9 +1,11 @@ package com.isaacandrade.blog.service; +import com.isaacandrade.blog.domain.projects.Project; import com.isaacandrade.blog.domain.technologies.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -24,16 +26,16 @@ public TechnologyDto createTechnology(CreateTechnologyDto data) { return mapToTechnologyDTO((List) savedTechnology); } - public Optional getTechnologyById(Long id) { - return technologyRepository.findById(id); - } + public TechnologyDto getAllTechnologies() { + List technology = technologyRepository.findAll(); - public List getAllTechnologies() { - return technologyRepository.findAll(); + return mapToTechnologyDTO(technology); } - public List getTechnologyByType(TechnologyType type) { - return technologyRepository.findByType(type); + public TechnologyDto getTechnologyByType(TechnologyType type) { + List technologies = technologyRepository.findByType(type); + + return mapToTechnologyDTO(technologies); } public Optional updateTechnology(Long id, Technology updatedTechnology) {