Skip to content

Commit

Permalink
fix: Corrigindo a estrutura dos dados retornados de Technology
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacAndra committed Sep 23, 2024
1 parent bfbc4e1 commit e6046a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -54,30 +54,6 @@ public ResponseEntity<TechnologyDto> 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<Technology> getTechnologyById(@PathVariable Long id) {
Optional<Technology> 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,
Expand All @@ -94,7 +70,7 @@ public ResponseEntity<Technology> 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),
Expand All @@ -103,8 +79,10 @@ public ResponseEntity<Technology> getTechnologyById(@PathVariable Long id) {
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content),
}
)
public ResponseEntity<List<Technology>> getAllTechnologies() {
List<Technology> technologies = technologyService.getAllTechnologies();
public ResponseEntity<TechnologyDto> getAllTechnologies() {

TechnologyDto technologies = technologyService.getAllTechnologies();

return ResponseEntity.ok(technologies);
}

Expand All @@ -114,7 +92,7 @@ public ResponseEntity<List<Technology>> 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),
Expand All @@ -123,9 +101,11 @@ public ResponseEntity<List<Technology>> getAllTechnologies() {
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content),
}
)
public ResponseEntity<List<Technology>> getTechnologyByType(@PathVariable String type) {
public ResponseEntity<TechnologyDto> getTechnologyByType(@PathVariable String type) {

TechnologyType technologyType = TechnologyType.valueOf(type.toUpperCase());
List<Technology> technologies = technologyService.getTechnologyByType(technologyType);
TechnologyDto technologies = technologyService.getTechnologyByType(technologyType);

return ResponseEntity.ok(technologies);
}

Expand All @@ -142,7 +122,7 @@ public ResponseEntity<List<Technology>> 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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,16 +26,16 @@ public TechnologyDto createTechnology(CreateTechnologyDto data) {
return mapToTechnologyDTO((List<Technology>) savedTechnology);
}

public Optional<Technology> getTechnologyById(Long id) {
return technologyRepository.findById(id);
}
public TechnologyDto getAllTechnologies() {
List<Technology> technology = technologyRepository.findAll();

public List<Technology> getAllTechnologies() {
return technologyRepository.findAll();
return mapToTechnologyDTO(technology);
}

public List<Technology> getTechnologyByType(TechnologyType type) {
return technologyRepository.findByType(type);
public TechnologyDto getTechnologyByType(TechnologyType type) {
List<Technology> technologies = technologyRepository.findByType(type);

return mapToTechnologyDTO(technologies);
}

public Optional<Technology> updateTechnology(Long id, Technology updatedTechnology) {
Expand Down

0 comments on commit e6046a0

Please sign in to comment.