Skip to content

Commit e6f49e1

Browse files
Configurado o cacheEvict e aplicado ao projeto o spring security e configurado o mesmo
1 parent 2da49a2 commit e6f49e1

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

testeSantanderWay/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343
<artifactId>spring-boot-starter-web</artifactId>
4444
</dependency>
4545

46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-cache</artifactId>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-security</artifactId>
54+
</dependency>
55+
56+
4657
<dependency>
4758
<groupId>org.springframework.boot</groupId>
4859
<artifactId>spring-boot-starter-web-services</artifactId>

testeSantanderWay/src/main/java/br/com/testesantanderway/TesteSantanderWayApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cache.annotation.EnableCaching;
56
import org.springframework.data.web.config.EnableSpringDataWebSupport;
67

78
@SpringBootApplication
89
@EnableSpringDataWebSupport
10+
@EnableCaching
911
public class TesteSantanderWayApplication {
1012
public static void main(String[] args) {
1113
SpringApplication.run(TesteSantanderWayApplication.class, args);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package br.com.testesantanderway.config.security;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
5+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
6+
7+
@EnableWebSecurity
8+
@Configuration
9+
public class ConfigSeguranca extends WebSecurityConfigurerAdapter {
10+
11+
}

testeSantanderWay/src/main/java/br/com/testesantanderway/controller/LoginCliente.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import br.com.testesantanderway.modelo.Cliente;
99
import br.com.testesantanderway.repository.ClienteRepository;
1010
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.cache.annotation.CacheEvict;
12+
import org.springframework.cache.annotation.Cacheable;
1113
import org.springframework.data.domain.Page;
1214
import org.springframework.data.domain.Pageable;
1315
import org.springframework.data.domain.Sort;
@@ -28,6 +30,7 @@ public class LoginCliente {
2830
private ClienteRepository clienteRepository;
2931

3032
@GetMapping
33+
@Cacheable(value = "listaDeCliente")
3134
public Page<ClienteDTO> dadosLoginCliente(@RequestParam(required = false) String nome, @PageableDefault(sort = "codigoUsuario",
3235
direction = Sort.Direction.ASC) Pageable paginacao) {
3336

@@ -62,6 +65,7 @@ public ResponseEntity<DetalheClienteDTO> detalhe(@PathVariable String id) {
6265
}
6366

6467
@PutMapping("/{id}")
68+
@CacheEvict(value = "listaDeCliente", allEntries = true)
6569
public ResponseEntity<ClienteDTO> atualizar(@PathVariable String id, @RequestBody @Valid AtualizacaoClienteForm form) {
6670
Optional<Cliente> optional = clienteRepository.findById(id);
6771
if (optional.isPresent()) {
@@ -73,6 +77,7 @@ public ResponseEntity<ClienteDTO> atualizar(@PathVariable String id, @RequestBod
7377
}
7478

7579
@DeleteMapping("/{id}")
80+
@CacheEvict(value = "listaDeCliente", allEntries = true)
7681
public ResponseEntity<?> remover(@PathVariable String id) {
7782
Optional<Cliente> optional = clienteRepository.findById(id);
7883
if (optional.isPresent()) {

0 commit comments

Comments
 (0)