File tree Expand file tree Collapse file tree 5 files changed +28
-6
lines changed
main/java/br/com/testesantanderway
test/java/br/com/testesantanderway/config Expand file tree Collapse file tree 5 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -32,12 +32,13 @@ public class GastoController {
3232 @ Autowired
3333 private GastoService gastoService ;
3434
35+ //TODO permitir apenas USUARIO listar gastos
3536 @ GetMapping
36- public Page < GastoDTO > listagemDeGastos (HttpServletRequest request ) {
37+ public ResponseEntity < List < GastoDTO > > listagemDeGastos (HttpServletRequest request ) {
3738 String codigoUsuario = servicoDeToken .getCodigo (AutenticacaoViaTokenFilter .recuperarToken (request ));
3839 LocalDateTime ultimosCincoSegundos = LocalDateTime .now ().minusSeconds (5 );
3940 List <Gasto > gastos = gastoRepository .findByCodigoUsuarioAndDataCriacaoAfter (codigoUsuario , ultimosCincoSegundos );
40- return GastoDTO .converter (gastos );
41+ return ResponseEntity . ok ( GastoDTO .converter (gastos ) );
4142 }
4243
4344 //TODO permitir apenas SISTEMA lançar gasto
Original file line number Diff line number Diff line change @@ -52,11 +52,12 @@ public void setCategoria(String categoria) {
5252 this .categoria = categoria ;
5353 }
5454
55- public static List <GastoDTO > converterLista (List <Gasto > gastos ) {
55+ public static List <GastoDTO > converter (List <Gasto > gastos ) {
5656 return gastos .stream ().map (GastoDTO ::new ).collect (Collectors .toList ());
5757 }
5858
59- public static Page <GastoDTO > converterPagina (Page <Gasto > gastos ) {
59+ public static Page <GastoDTO > converter (Page <Gasto > gastos ) {
6060 return gastos .map (GastoDTO ::new );
6161 }
62+
6263}
Original file line number Diff line number Diff line change 11package br .com .testesantanderway .repository ;
22
33import br .com .testesantanderway .modelo .Gasto ;
4+ import org .springframework .cache .annotation .Cacheable ;
45import org .springframework .data .domain .Page ;
56import org .springframework .data .domain .Pageable ;
67import org .springframework .data .solr .repository .SolrCrudRepository ;
1213public interface GastoRepository extends SolrCrudRepository <Gasto , String >{
1314 List <Gasto > findByCodigoUsuarioAndDataCriacaoAfter (String codigoUsuario , LocalDateTime dataCriacao );
1415
16+ @ Cacheable ("gastoUsuario" )
1517 Page <Gasto > findByDataCriacao (String data , Pageable paginacao );
1618
1719 Optional <String > findCategoriaByDescricao (String descricao );
Original file line number Diff line number Diff line change 11package br .com .testesantanderway .service ;
22
3+ import br .com .testesantanderway .config .security .AutenticacaoViaTokenFilter ;
4+ import br .com .testesantanderway .dto .GastoDTO ;
35import br .com .testesantanderway .modelo .Gasto ;
46import br .com .testesantanderway .repository .GastoRepository ;
57import org .springframework .beans .factory .annotation .Autowired ;
8+ import org .springframework .http .ResponseEntity ;
69import org .springframework .stereotype .Service ;
710
11+ import javax .servlet .http .HttpServletRequest ;
12+ import java .time .LocalDateTime ;
13+ import java .util .List ;
814import java .util .Optional ;
915
1016@ Service
@@ -16,7 +22,11 @@ public class GastoService {
1622 public void lancarGastosCartao (Gasto gasto ) {
1723 integrarCategoria (gasto );
1824 gastoRepository .save (gasto );
25+ }
1926
27+ public List <Gasto > listarGastosMaisRecentes (String codigoUsuario ) {
28+ LocalDateTime ultimosCincoSegundos = LocalDateTime .now ().minusSeconds (5 );
29+ return gastoRepository .findByCodigoUsuarioAndDataCriacaoAfter (codigoUsuario , ultimosCincoSegundos );
2030 }
2131
2232 private void integrarCategoria (Gasto gasto ){
Original file line number Diff line number Diff line change 22
33import br .com .testesantanderway .modelo .Gasto ;
44import br .com .testesantanderway .service .GastoService ;
5+ import io .jsonwebtoken .lang .Assert ;
56import org .junit .jupiter .api .BeforeEach ;
67import org .junit .jupiter .api .DisplayName ;
78import org .junit .jupiter .api .Test ;
@@ -19,13 +20,16 @@ public class TesteGasto {
1920
2021 private Gasto gasto ;
2122
23+ private String codigoUsuario ;
24+
2225 @ BeforeEach
2326 public void setup (){
27+ this .codigoUsuario = UUID .randomUUID ().toString ();
2428 this .gasto = new Gasto ();
2529 this .gasto .setDataCriacao (LocalDateTime .now ());
2630 this .gasto .setDescricao ("Teste Unitario" );
2731 this .gasto .setValor (10.0 );
28- this .gasto .setCodigoUsuario (UUID . randomUUID (). toString () );
32+ this .gasto .setCodigoUsuario (this . codigoUsuario );
2933 this .gasto .setCodigoSistema (UUID .randomUUID ().toString ());
3034 }
3135
@@ -35,6 +39,10 @@ public void testarLancamentoDeGasto(){
3539 service .lancarGastosCartao (this .gasto );
3640 }
3741
38- //TODO testar categorizacao automatica
42+ @ DisplayName ("Testa o Serviço de Listagem de Gastos" )
43+ @ Test
44+ public void testarListagemDeGastos (){
45+ service .listarGastosMaisRecentes (this .codigoUsuario );
46+ }
3947
4048}
You can’t perform that action at this time.
0 commit comments