-
Notifications
You must be signed in to change notification settings - Fork 54
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
1 parent
40dcb06
commit 72b6632
Showing
9 changed files
with
317 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
version: '3' | ||
services: | ||
|
||
zookeeper: | ||
image: "confluentinc/cp-zookeeper:5.2.1" | ||
environment: | ||
ZOOKEEPER_CLIENT_PORT: 2181 | ||
ZOOKEEPER_TICK_TIME: 2000 | ||
ZOOKEEPER_SYNC_LIMIT: 2 | ||
|
||
kafka: | ||
image: "confluentinc/cp-kafka:5.2.1" | ||
ports: | ||
- 9092:9092 | ||
depends_on: | ||
- zookeeper | ||
environment: | ||
KAFKA_BROKER_ID: 1 | ||
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181" | ||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT | ||
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1" | ||
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true" | ||
|
||
postgres: | ||
image: 'postgres:alpine' | ||
volumes: | ||
- postgres-volume:/var/lib/postgresql/data | ||
ports: | ||
- 5432:5432 | ||
environment: | ||
POSTGRES_USER: keyclospring.datasource.username= | ||
spring.datasource.password=ak | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: keycloak | ||
POSTGRES_HOST: postgres | ||
|
||
keycloak: | ||
image: jboss/keycloak | ||
ports: | ||
- 18443:8443 | ||
- 18080:8080 | ||
- 19990:9990 | ||
depends_on: | ||
# Just a delay to wait for postgres! This is not recommended! | ||
- grafana | ||
- prometheus | ||
- jaeger | ||
- kafka | ||
- zookeeper | ||
- contas | ||
- analise | ||
- transacoes | ||
- postgres | ||
environment: | ||
DB_VENDOR: postgres | ||
DB_ADDR: postgres | ||
DB_PORT: 5432 | ||
DB_DATABASE: keycloak | ||
DB_USER: keycloak | ||
DB_PASSWORD: password | ||
KEYCLOAK_USER: admin | ||
KEYCLOAK_PASSWORD: Pa55w0rd | ||
POSTGRES_PORT_5432_TCP_ADDR: 127.0.0.1 | ||
|
||
analise: | ||
image: 'zupacademy/analise-financeira' | ||
ports: | ||
- 9999:9999 | ||
environment: | ||
SERVER_PORT: 9999 | ||
LOG_LEVEL: INFO | ||
URL_SISTEMA_CARTAO: http://contas:8888/api/cartoes | ||
JAEGER_ENDPOINT: http://jaeger:14268/api/traces | ||
|
||
contas: | ||
image: 'zupacademy/contas' | ||
ports: | ||
- 8888:8888 | ||
environment: | ||
SERVER_PORT: 8888 | ||
LOG_LEVEL: INFO | ||
JAEGER_ENDPOINT: http://jaeger:14268/api/traces | ||
|
||
transacoes: | ||
image: 'zupacademy/transacoes' | ||
ports: | ||
- 7777:7777 | ||
depends_on: | ||
- kafka | ||
environment: | ||
SERVER_PORT: 7777 | ||
LOG_LEVEL: INFO | ||
KAFKA_HOST: "kafka:29092" | ||
JAEGER_ENDPOINT: http://jaeger:14268/api/traces | ||
|
||
jaeger: | ||
image: jaegertracing/all-in-one | ||
ports: | ||
- 5775:5775/udp | ||
- 6831:6831/udp | ||
- 6832:6832/udp | ||
- 5778:5778 | ||
- 16686:16686 | ||
- 14268:14268 | ||
- 14250:14250 | ||
- 9411:9411 | ||
environment: | ||
COLLECTOR_ZIPKIN_HTTP_PORT: 9411 | ||
|
||
prometheus: | ||
image: prom/prometheus | ||
volumes: | ||
- prometheus-volume:/etc/prometheus/ | ||
network_mode: bridge | ||
ports: | ||
- "9090:9090" | ||
|
||
grafana: | ||
image: grafana/grafana | ||
volumes: | ||
- grafana-volume:/var/lib/grafana | ||
network_mode: bridge | ||
ports: | ||
- "3000:3000" | ||
depends_on: | ||
- prometheus | ||
|
||
vault: | ||
image: vault:1.5.3 | ||
ports: | ||
# - 8200:8200 | ||
- 8202:8202 | ||
environment: | ||
VAULT_DEV_ROOT_TOKEN_ID: ee413645-dbe8-4848-afc6-6bb2768ada75 | ||
VAULT_TOKEN: ee413645-dbe8-4848-afc6-6bb2768ada75 | ||
VAULT_ADDR: http://127.0.0.1:8200 | ||
|
||
volumes: | ||
grafana-volume: | ||
prometheus-volume: | ||
postgres-volume: |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/br/com/zupacademy/william/proposta/Proposta.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,37 @@ | ||
package br.com.zupacademy.william.proposta; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import java.math.BigDecimal; | ||
|
||
@Entity | ||
public class Proposta { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String documento; | ||
private String email; | ||
private String nome; | ||
private String endereco; | ||
private BigDecimal salario; | ||
|
||
public Proposta(String documento, String email, String nome, String endereco, BigDecimal salario) { | ||
this.documento = documento; | ||
this.email = email; | ||
this.nome = nome; | ||
this.endereco = endereco; | ||
this.salario = salario; | ||
} | ||
|
||
@Deprecated | ||
public Proposta() { | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/br/com/zupacademy/william/proposta/PropostaController.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,32 @@ | ||
package br.com.zupacademy.william.proposta; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import javax.transaction.Transactional; | ||
import javax.validation.Valid; | ||
import java.net.URI; | ||
|
||
@RestController | ||
@RequestMapping("/propostas") | ||
public class PropostaController { | ||
|
||
@Autowired | ||
private PropostaRepository propostaRepository; | ||
|
||
@Transactional | ||
@PostMapping | ||
public ResponseEntity criar(UriComponentsBuilder uriComponentsBuilder, | ||
@RequestBody @Valid PropostaRequest propostaRequest) { | ||
Proposta proposta = propostaRequest.toModel(); | ||
Proposta novaProposta = propostaRepository.save(proposta); | ||
URI enderecoRecurso = uriComponentsBuilder.path("/propostas/{id}").build(novaProposta.getId()); | ||
|
||
return ResponseEntity.created(enderecoRecurso).build(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/br/com/zupacademy/william/proposta/PropostaRepository.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 br.com.zupacademy.william.proposta; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PropostaRepository extends JpaRepository<Proposta, Long> { | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/br/com/zupacademy/william/proposta/PropostaRequest.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,42 @@ | ||
package br.com.zupacademy.william.proposta; | ||
|
||
import br.com.zupacademy.william.proposta.validation.CpfCnpj; | ||
|
||
import javax.validation.constraints.Email; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Positive; | ||
import java.math.BigDecimal; | ||
|
||
public class PropostaRequest { | ||
|
||
// @NotBlank | ||
@CpfCnpj | ||
private String documento; | ||
|
||
// @NotBlank | ||
private String email; | ||
|
||
@NotBlank | ||
private String nome; | ||
|
||
@NotBlank | ||
private String endereco; | ||
|
||
@NotNull | ||
@Positive | ||
private BigDecimal salario; | ||
|
||
public PropostaRequest(String documento, String email, String nome, String endereco, BigDecimal salario) { | ||
this.documento = documento; | ||
this.email = email; | ||
this.nome = nome; | ||
this.endereco = endereco; | ||
this.salario = salario; | ||
} | ||
|
||
public Proposta toModel() { | ||
return new Proposta(this.documento, this.email, this.nome, this.endereco, this.salario); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/br/com/zupacademy/william/proposta/validation/CpfCnpj.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,31 @@ | ||
package br.com.zupacademy.william.proposta.validation; | ||
|
||
import org.hibernate.validator.constraints.CompositionType; | ||
import org.hibernate.validator.constraints.ConstraintComposition; | ||
import org.hibernate.validator.constraints.br.CNPJ; | ||
import org.hibernate.validator.constraints.br.CPF; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Documented | ||
@Target({FIELD}) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = {}) | ||
@ConstraintComposition(CompositionType.OR) | ||
@CPF | ||
@CNPJ | ||
public @interface CpfCnpj { | ||
|
||
String message() default "a"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
|
||
spring.jpa.generate-ddl=true | ||
spring.jpa.show-sql=true | ||
spring.jpa.hibernate.ddl-auto=create-drop |
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,11 @@ | ||
NotBlank={0} é obrigatório(a) | ||
NotNull={0} é obrigatório(a) | ||
Email={0} deve ser um e-mail válido | ||
Positive={0} deve ser maior que 0 | ||
|
||
#PropostaRequest | ||
propostaRequest.documento=Documento do dono da proposta | ||
propostaRequest.email=Email do dono da proposta | ||
propostaRequest.nome=Nome do dono da proposta | ||
propostaRequest.endereco=Endereço do dono da proposta | ||
propostaRequest.salario=Salário do dono da proposta |