-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Services e Controllers das novas Entidades Implementados
- Loading branch information
1 parent
d9bf7ef
commit ba86cd5
Showing
10 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
src/main/java/com/isaacandrade/blog/controller/ProjectController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package com.isaacandrade.blog.controller; | ||
|
||
import com.isaacandrade.blog.domain.projects.CreateProjectDto; | ||
import com.isaacandrade.blog.domain.projects.ProjectDto; | ||
import com.isaacandrade.blog.domain.user.UserDTO; | ||
import com.isaacandrade.blog.service.ProjectService; | ||
import com.isaacandrade.blog.utils.MediaType; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/projects") | ||
@Tag(name = "Projetos" , description = "Endpoints para Gerenciar os Projetos") | ||
public class ProjectController { | ||
|
||
@Autowired | ||
ProjectService projectService; | ||
|
||
|
||
@GetMapping( | ||
produces = {MediaType.APPLICATION_JSON, | ||
MediaType.APPLICATION_XML, | ||
MediaType.APPLICATION_YML | ||
} | ||
) | ||
@Operation( | ||
summary = "Encontre todos os Projetos", | ||
description = "Encontre todos os Projetos", | ||
tags = {"Projetos"}, | ||
responses = { | ||
@ApiResponse( | ||
description = "Success", | ||
responseCode = "200", | ||
content = @Content( | ||
mediaType = "application/json", | ||
array = @ArraySchema(schema = @Schema(implementation = ProjectDto.class)) | ||
) | ||
), | ||
@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<List<ProjectDto>> getAllProjects(){ | ||
List<ProjectDto> projects = projectService.getAllProjects(); | ||
return ResponseEntity.ok(projects); | ||
} | ||
|
||
|
||
@GetMapping( | ||
value = "/{id}", | ||
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML} | ||
) | ||
@Operation(summary = "Encontre o Projeto pelo Id", description = "Encontre o Usuário pelo Id", | ||
tags = {"Projetos"}, | ||
responses = { | ||
@ApiResponse(description = "Success", responseCode = "200", | ||
content = @Content(schema = @Schema(implementation = ProjectDto.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<ProjectDto> getProjectById(@PathVariable Long id) { | ||
ProjectDto projectById = projectService.getProjectById(id); | ||
|
||
return ResponseEntity.ok(projectById); | ||
} | ||
|
||
|
||
@PostMapping( | ||
consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML}, | ||
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML} | ||
) | ||
@Transactional | ||
@Operation( | ||
summary = "Cria um novo projeto", | ||
description = "Cria um novo projeto passando uma representação em JSON, XML ou YML ", | ||
tags = {"Projetos"}, | ||
responses = { | ||
@ApiResponse(description = "Success", responseCode = "200", | ||
content = @Content(schema = @Schema(implementation = ProjectDto.class)) | ||
), | ||
@ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), | ||
@ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), | ||
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), | ||
} | ||
) | ||
public ResponseEntity<ProjectDto> createProject(@RequestBody CreateProjectDto data) { | ||
ProjectDto creatingProject = projectService.createProject(data); | ||
return new ResponseEntity<>(creatingProject, HttpStatus.CREATED); | ||
} | ||
|
||
@PutMapping( | ||
value = "/{id}", | ||
consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML}, | ||
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML} | ||
) | ||
@Transactional | ||
@Operation( | ||
summary = "Atualiza os dados de um projeto", | ||
description = "Atualiza os dados de um projeto passando uma representação em JSON, XML ou YML ", | ||
tags = {"Projetos"}, | ||
responses = { | ||
@ApiResponse(description = "Updated", responseCode = "200", | ||
content = @Content(schema = @Schema(implementation = ProjectDto.class)) | ||
), | ||
@ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), | ||
@ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), | ||
@ApiResponse(description = "Not Found", responseCode = "404", content = @Content), | ||
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), | ||
} | ||
) | ||
public ResponseEntity<Optional<ProjectDto>> updateProject(@PathVariable Long id, @RequestBody CreateProjectDto data) { | ||
Optional<ProjectDto> updatingProject = projectService.updateProject(id, data); | ||
|
||
return ResponseEntity.ok(updatingProject); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
@Operation( | ||
summary = "Deleta um projeto", | ||
description = "Deleta um projeto passando uma representação em JSON, XML ou YML ", | ||
tags = {"Projetos"}, | ||
responses = { | ||
@ApiResponse(description = "No Content", responseCode = "204", content = @Content), | ||
@ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), | ||
@ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), | ||
@ApiResponse(description = "Not Found", responseCode = "404", content = @Content), | ||
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), | ||
} | ||
) | ||
public ResponseEntity<ProjectDto> deleteProject(@PathVariable Long id) { | ||
projectService.deleteProject(id); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
177 changes: 177 additions & 0 deletions
177
src/main/java/com/isaacandrade/blog/controller/TechnologyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package com.isaacandrade.blog.controller; | ||
|
||
import com.isaacandrade.blog.domain.technologies.CreateTechnologyDto; | ||
import com.isaacandrade.blog.domain.technologies.Technology; | ||
import com.isaacandrade.blog.domain.technologies.TechnologyDto; | ||
import com.isaacandrade.blog.domain.technologies.TechnologyType; | ||
import com.isaacandrade.blog.service.TechnologyService; | ||
import com.isaacandrade.blog.utils.MediaType; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/technologies") | ||
@Tag(name = "Tecnologias" , description = "Endpoints para Gerenciar os Tecnologias") | ||
public class TechnologyController { | ||
|
||
@Autowired | ||
private TechnologyService technologyService; | ||
|
||
// Endpoint para criar uma nova tecnologia | ||
@PostMapping( | ||
consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML}, | ||
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML} | ||
) | ||
@Transactional | ||
@Operation( | ||
summary = "Cria uma nova Tecnologia", | ||
description = "Cria uma nova tecnologia passando uma representação em JSON, XML ou YML ", | ||
tags = {"Tecnologias"}, | ||
responses = { | ||
@ApiResponse(description = "Success", responseCode = "200", | ||
content = @Content(schema = @Schema(implementation = Technology.class)) | ||
), | ||
@ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), | ||
@ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), | ||
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), | ||
} | ||
) | ||
public ResponseEntity<TechnologyDto> createTechnology(@RequestBody CreateTechnologyDto data) { | ||
TechnologyDto createdTechnology = technologyService.createTechnology(data); | ||
|
||
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, | ||
MediaType.APPLICATION_XML, | ||
MediaType.APPLICATION_YML | ||
}) | ||
@Operation( | ||
summary = "Encontre todas as Tecnologias", | ||
description = "Encontre todas as Tecnologias", | ||
tags = {"Tecnologias"}, | ||
responses = { | ||
@ApiResponse( | ||
description = "Success", | ||
responseCode = "200", | ||
content = @Content( | ||
mediaType = "application/json", | ||
array = @ArraySchema(schema = @Schema(implementation = Technology.class)) | ||
) | ||
), | ||
@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<List<Technology>> getAllTechnologies() { | ||
List<Technology> technologies = technologyService.getAllTechnologies(); | ||
return ResponseEntity.ok(technologies); | ||
} | ||
|
||
// Endpoint para obter tecnologias por tipo | ||
@GetMapping("/type/{type}") | ||
@Operation(summary = "Encontre a Tecnologia pelo tipo", description = "Encontre a Tecnologia pelo tipo", | ||
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<List<Technology>> getTechnologyByType(@PathVariable String type) { | ||
TechnologyType technologyType = TechnologyType.valueOf(type.toUpperCase()); | ||
List<Technology> technologies = technologyService.getTechnologyByType(technologyType); | ||
return ResponseEntity.ok(technologies); | ||
} | ||
|
||
// Endpoint para atualizar uma tecnologia | ||
@PutMapping( | ||
value = "/{id}", | ||
consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML}, | ||
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_YML} | ||
) | ||
@Transactional | ||
@Operation( | ||
summary = "Atualiza os dados de uma tecnologia", | ||
description = "Atualiza os dados de uma tecnologia passando uma representação em JSON, XML ou YML ", | ||
tags = {"Tecnologias"}, | ||
responses = { | ||
@ApiResponse(description = "Updated", responseCode = "200", | ||
content = @Content(schema = @Schema(implementation = Technology.class)) | ||
), | ||
@ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), | ||
@ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), | ||
@ApiResponse(description = "Not Found", responseCode = "404", content = @Content), | ||
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), | ||
} | ||
) | ||
public ResponseEntity<Technology> updateTechnology(@PathVariable Long id, @RequestBody Technology updatedTechnology) { | ||
Optional<Technology> technology = technologyService.updateTechnology(id, updatedTechnology); | ||
return technology.map(ResponseEntity::ok) | ||
.orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build()); | ||
} | ||
|
||
// Endpoint para deletar uma tecnologia | ||
@DeleteMapping("/{id}") | ||
@Operation( | ||
summary = "Deleta uma tecnologia", | ||
description = "Deleta uma tecnologia passando uma representação em JSON, XML ou YML ", | ||
tags = {"Tecnologias"}, | ||
responses = { | ||
@ApiResponse(description = "No Content", responseCode = "204", content = @Content), | ||
@ApiResponse(description = "Bad Request", responseCode = "400", content = @Content), | ||
@ApiResponse(description = "Unauthorized", responseCode = "401", content = @Content), | ||
@ApiResponse(description = "Not Found", responseCode = "404", content = @Content), | ||
@ApiResponse(description = "Internal Error", responseCode = "500", content = @Content), | ||
} | ||
) | ||
public ResponseEntity<Void> deleteTechnology(@PathVariable Long id) { | ||
technologyService.deleteTechnology(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/isaacandrade/blog/domain/projects/CreateProjectDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.isaacandrade.blog.domain.projects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.isaacandrade.blog.domain.technologies.TechnologyDto; | ||
@JsonPropertyOrder({"name", "description", "technologies", "url", "url_github"}) | ||
public record CreateProjectDto( | ||
@JsonProperty(value = "name") | ||
String name, | ||
@JsonProperty(value = "description") | ||
String description, | ||
|
||
@JsonProperty(value = "technologies") | ||
TechnologyDto technologies, | ||
|
||
@JsonProperty(value = "url") | ||
String url, | ||
@JsonProperty(value = "url_github") | ||
String urlGitHub | ||
) { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/isaacandrade/blog/domain/projects/ProjectDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.isaacandrade.blog.domain.projects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.isaacandrade.blog.domain.technologies.TechnologyDto; | ||
|
||
@JsonPropertyOrder({"id", "name", "description", "technologies", "url", "url_github"}) | ||
public record ProjectDto( | ||
@JsonProperty(value = "id") | ||
Long id, | ||
|
||
@JsonProperty(value = "name") | ||
String name, | ||
@JsonProperty(value = "description") | ||
String description, | ||
|
||
@JsonProperty(value = "technologies") | ||
TechnologyDto technologies, | ||
|
||
@JsonProperty(value = "url") | ||
String url, | ||
@JsonProperty(value = "url_github") | ||
String gitHub | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/isaacandrade/blog/domain/projects/ProjectRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.isaacandrade.blog.domain.projects; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProjectRepository extends JpaRepository<Project, Long> { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/isaacandrade/blog/domain/technologies/CreateTechnologyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.isaacandrade.blog.domain.technologies; | ||
|
||
public record CreateTechnologyDto( | ||
String name, | ||
TechnologyType type | ||
|
||
) { | ||
|
||
} |
Oops, something went wrong.