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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.montanha</groupId> | |
<artifactId>gerenciador-viagens-montanha</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<packaging>jar</packaging> |
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
package com.montanha.gerenciador; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.boot.autoconfigure.domain.EntityScan; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
@SpringBootApplication | |
@Configuration |
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
package com.montanha.gerenciador.entities; | |
import java.io.Serializable; | |
import java.util.Date; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
import javax.persistence.Table; | |
import org.springframework.stereotype.Component; |
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
package com.montanha.gerenciador.controller; | |
import java.net.URI; | |
import java.util.List; | |
import javax.validation.Valid; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.validation.BindingResult; | |
import org.springframework.web.bind.annotation.GetMapping; |
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
@Autowired | |
private ViagemServices viagemService; | |
@PostMapping(path = "/new") | |
public ResponseEntity<Response<Viagem>> cadastrar(@Valid @RequestBody ViagemDto viagemDto, BindingResult result) { | |
Response<Viagem> response = new Response<Viagem>(); | |
if (result.hasErrors()) { | |
result.getAllErrors().forEach(error -> response.getErrors().add(error.getDefaultMessage())); | |
return ResponseEntity.badRequest().body(response); |
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
package com.montanha.gerenciador.services; | |
import java.util.List; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
import com.montanha.gerenciador.dtos.ViagemDto; | |
import com.montanha.gerenciador.entities.Viagem; | |
import com.montanha.gerenciador.repositories.ViagemRepository; | |
import com.montanha.gerenciador.services.exceptions.ViagemServiceException; |
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
package com.montanha.gerenciador.dtos; | |
import java.io.Serializable; | |
import java.util.Date; | |
import javax.validation.constraints.NotNull; | |
import org.hibernate.validator.constraints.Length; | |
import com.fasterxml.jackson.annotation.JsonFormat; | |
public class ViagemDto implements Serializable { |
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
package com.montanha.gerenciador.repositories; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.stereotype.Repository; | |
import com.montanha.gerenciador.entities.Viagem; | |
@Repository | |
public interface ViagemRepository extends JpaRepository<Viagem, Long> { | |
Viagem findByLocalDeDestino(String localDeDestino); |
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
public class GerenciadorViagemController { | |
@Autowired | |
private ViagemServices viagemService; | |
@PostMapping(path = "/new") | |
public ResponseEntity<Response<Viagem>> cadastrar(@Valid @RequestBody ViagemDto viagemDto, BindingResult result) { | |
Response<Viagem> response = new Response<Viagem>(); | |
if (result.hasErrors()) { |
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
package com.montanha.gerenciador.responses; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Response<T> { | |
private T data; | |
private List<String> errors; |
OlderNewer