Skip to content

Commit

Permalink
Notificação aviso de viagem v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
giovnnvm committed Aug 3, 2021
1 parent b659d55 commit c064fbd
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.feign.requests;
package br.com.zupacademy.giovannimoratto.desafioproposta.Bloqueio;

import javax.validation.constraints.NotBlank;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses;
package br.com.zupacademy.giovannimoratto.desafioproposta.Bloqueio;

import br.com.zupacademy.giovannimoratto.desafioproposta.Bloqueio.BloqueioStatus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoRepository;
import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoStatus;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.CartoesFeignClient;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.requests.BloqueioClientRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses.BloqueioClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.proposta.PropostaController;
import feign.FeignException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -55,7 +53,7 @@ public ResponseEntity <?> solicitacaoDeBloqueio(@PathVariable Long id,
logger.info("Requisição de bloqueio convertida em classe de dominio");

bloqueioRepository.save(solicitacaoBloqueio);
logger.info("Requisição de bloqueio persistida no banco de dados");
logger.info("Bloqueio persistido no banco de dados");

cartao.bloquear();
logger.info("Cartão bloqueado");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses;
package br.com.zupacademy.giovannimoratto.desafioproposta.aviso;

/**
* @Author giovanni.moratto
*/

public class AvisoClientResponse {

private String resultado;
private AvisoStatus resultado;

@Deprecated
public AvisoClientResponse() {
}

public AvisoClientResponse(String resultado) {
public AvisoClientResponse(AvisoStatus resultado) {
this.resultado = resultado;
}

public String getResultado() {
public AvisoStatus getResultado() {
return resultado;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoModel;
import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoRepository;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.CartoesFeignClient;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses.AvisoClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.proposta.PropostaController;
import feign.FeignException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -24,6 +26,8 @@
@RequestMapping("/api")
public class AvisoController {

private final Logger logger = LoggerFactory.getLogger(PropostaController.class);

@Autowired
private CartaoRepository cartaoRepository;
@Autowired
Expand All @@ -35,19 +39,27 @@ public class AvisoController {
public ResponseEntity <?> avisarViagem(@PathVariable Long id, @RequestBody @Valid AvisoRequest bodyRequest,
HttpServletRequest httpRequest) {

CartaoModel cartao = cartaoRepository.findById(id).orElseThrow(()
-> new ResponseStatusException(NOT_FOUND, "Este cartão não existe."));

CartaoModel cartao = verificaSeCartaoExiste(id);
logger.info("Cartão encontrado");
notificaAvisoDeViagem(cartao, bodyRequest);
AvisoModel novoAviso = bodyRequest.toModel(cartao, httpRequest);
logger.info("Requisição de aviso de viagem convertida em classe de dominio");
novoAviso = avisoRepository.save(novoAviso);
logger.info("Aviso de viagem persistida no banco de dados");
return ResponseEntity.ok().build();
}

private CartaoModel verificaSeCartaoExiste(Long id) {
logger.info("Buscando cartão por ID...");
return cartaoRepository.findById(id).orElseThrow(() ->
new ResponseStatusException(NOT_FOUND, "Este cartão não existe"));
}

private void notificaAvisoDeViagem(CartaoModel cartao, AvisoRequest bodyRequest) {
logger.info("Notificação de aviso de viagem enviada ao cliente");
try {
AvisoClientResponse resultado = feignClient.notificacaoDeAviso(cartao.getNumero(), bodyRequest);

logger.info("Resultado da notificação: {}", resultado.getResultado());
} catch (FeignException e) {
throw new ResponseStatusException(UNPROCESSABLE_ENTITY, "Falha no sistema");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ public AvisoModel toModel(CartaoModel cartao, HttpServletRequest httpRequest) {
String ipClient = httpRequest.getRemoteAddr();
return new AvisoModel(destino, validoAte, ipClient, userAgent, cartao);
}
}

public String getDestino() {
return destino;
}

public LocalDate getValidoAte() {
return validoAte;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.aviso;

/**
* @Author giovanni.moratto
*/

public enum AvisoStatus {
CRIADO,
FALHA;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ResponseEntity <?> cadastraBiometria(@PathVariable("id") Long id,
BiometriaModel novaBiometria = request.toModel(cartao);
logger.info("Requisição de biometria convertida em classe de dominio");
repository.save(novaBiometria);
logger.info("Requisição de biometria persistida no banco de dados");
logger.info("Biometria persistida no banco de dados");
URI uri = uriBuilder.path("/biometria/{id}").buildAndExpand(novaBiometria.getId()).toUri();
return ResponseEntity.created(uri).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses;
package br.com.zupacademy.giovannimoratto.desafioproposta.cartao;

import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoModel;
import br.com.zupacademy.giovannimoratto.desafioproposta.proposta.PropostaModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.feign;

import br.com.zupacademy.giovannimoratto.desafioproposta.aviso.AvisoRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.requests.AnaliseClientRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.requests.BloqueioClientRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses.AvisoClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses.BloqueioClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses.CartaoClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.proposta.AnaliseClientRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.Bloqueio.BloqueioClientRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.aviso.AvisoClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.Bloqueio.BloqueioClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoClientResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.feign;

import br.com.zupacademy.giovannimoratto.desafioproposta.feign.requests.AnaliseClientRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.proposta.AnaliseClientRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.feign.requests;
package br.com.zupacademy.giovannimoratto.desafioproposta.proposta;

import javax.validation.constraints.NotBlank;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ResponseEntity <?> cadastraProposta(@RequestBody @Valid PropostaRequest r
PropostaModel novaProposta = request.toModel();
logger.info("Requisição de proposta convertida em classe de dominio");
repository.save(novaProposta);
logger.info("Requisição de proposta persistida no banco de dados");
logger.info("Proposta persistida no banco de dados");
logger.info("Verificando status da requisição de proposta");
verificaRestricao(novaProposta);
URI uri = uriBuilder.path("/proposta/{id}").buildAndExpand(novaProposta.getId()).toUri();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.proposta;

import br.com.zupacademy.giovannimoratto.desafioproposta.feign.requests.AnaliseClientRequest;
import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoModel;
import com.fasterxml.jackson.annotation.JsonManagedReference;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package br.com.zupacademy.giovannimoratto.desafioproposta.shedule;

import br.com.zupacademy.giovannimoratto.desafioproposta.feign.responses.CartaoClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.cartao.CartaoClientResponse;
import br.com.zupacademy.giovannimoratto.desafioproposta.feign.CartoesFeignClient;
import br.com.zupacademy.giovannimoratto.desafioproposta.proposta.PropostaModel;
import br.com.zupacademy.giovannimoratto.desafioproposta.proposta.PropostaRepository;
Expand Down

0 comments on commit c064fbd

Please sign in to comment.