Skip to content

Commit

Permalink
feat: cadastro de proposta
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidawilliam committed May 5, 2021
1 parent 40dcb06 commit 72b6632
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 2 deletions.
142 changes: 142 additions & 0 deletions docker-compose.yml
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:
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
<version>0.0.1-SNAPSHOT</version>
<name>proposta</name>
<description>Implementando o desafio Proposta</description>

<properties>
<java.version>11</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -32,17 +35,26 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.18.Final</version>
</dependency>

</dependencies>

<build>
<plugins>
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/br/com/zupacademy/william/proposta/Proposta.java
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;
}
}
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();
}
}
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> {
}
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
@Email
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);
}
}
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 {};
}
4 changes: 3 additions & 1 deletion src/main/resources/application.properties
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
11 changes: 11 additions & 0 deletions src/main/resources/messages.properties
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

0 comments on commit 72b6632

Please sign in to comment.