-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
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
41 changes: 41 additions & 0 deletions
41
src/main/java/br/com/zupacademy/fabiano/proposta/dto/AvisoViagemRegisterDto.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,41 @@ | ||
package br.com.zupacademy.fabiano.proposta.dto; | ||
|
||
import br.com.zupacademy.fabiano.proposta.modelo.AvisoViagem; | ||
import br.com.zupacademy.fabiano.proposta.modelo.Cartao; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import javax.validation.constraints.Future; | ||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
|
||
public class AvisoViagemRegisterDto { | ||
@NotNull | ||
@NotEmpty | ||
private String destino; | ||
@NotNull | ||
@Future | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") | ||
private LocalDate terminoViagem; | ||
|
||
public AvisoViagemRegisterDto() { | ||
} | ||
|
||
public AvisoViagemRegisterDto(@NotNull @NotEmpty String destino, | ||
@NotNull @Future @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate terminoViagem) { | ||
this.destino = destino; | ||
this.terminoViagem = terminoViagem; | ||
} | ||
|
||
public AvisoViagem converter(String userAgent, String remoteAddr, Cartao cartao) { | ||
return new AvisoViagem(this.destino, this.terminoViagem, userAgent, remoteAddr, cartao); | ||
} | ||
|
||
public String getDestino() { | ||
return destino; | ||
} | ||
|
||
public LocalDate getTerminoViagem() { | ||
return terminoViagem; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/br/com/zupacademy/fabiano/proposta/modelo/AvisoViagem.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,80 @@ | ||
package br.com.zupacademy.fabiano.proposta.modelo; | ||
|
||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToOne; | ||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
public class AvisoViagem { | ||
@Id | ||
@GeneratedValue(generator = "UUID") | ||
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") | ||
private String id; | ||
@NotNull | ||
@NotEmpty | ||
private String destinho; | ||
@NotNull | ||
private LocalDate terminoViagem; | ||
@CreationTimestamp | ||
private LocalDateTime createdAt; | ||
@NotNull | ||
@NotEmpty | ||
private String userAgent; | ||
@NotNull | ||
@NotEmpty | ||
private String ipCliente; | ||
@NotNull | ||
@ManyToOne | ||
private Cartao cartao; | ||
|
||
public AvisoViagem() { | ||
} | ||
|
||
public AvisoViagem(String destinho, | ||
@NotNull LocalDate terminoViagem, | ||
@NotNull @NotEmpty String userAgent, | ||
@NotNull @NotEmpty String ipCliente, | ||
@NotNull Cartao cartao) { | ||
this.destinho = destinho; | ||
this.terminoViagem = terminoViagem; | ||
this.userAgent = userAgent; | ||
this.ipCliente = ipCliente; | ||
this.cartao = cartao; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getDestinho() { | ||
return destinho; | ||
} | ||
|
||
public LocalDate getTerminoViagem() { | ||
return terminoViagem; | ||
} | ||
|
||
public LocalDateTime getCreatedAt() { | ||
return createdAt; | ||
} | ||
|
||
public String getUserAgent() { | ||
return userAgent; | ||
} | ||
|
||
public String getIpCliente() { | ||
return ipCliente; | ||
} | ||
|
||
public Cartao getCartao() { | ||
return cartao; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/br/com/zupacademy/fabiano/proposta/repository/AvisoViagemRepository.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,7 @@ | ||
package br.com.zupacademy.fabiano.proposta.repository; | ||
|
||
import br.com.zupacademy.fabiano.proposta.modelo.AvisoViagem; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AvisoViagemRepository extends JpaRepository<AvisoViagem, String> { | ||
} |