Skip to content

Commit f8c2500

Browse files
committed
feat: data exclusion endpoint; fix messages; minor improvements
1 parent ea8daff commit f8c2500

File tree

9 files changed

+38
-8
lines changed

9 files changed

+38
-8
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
</parent>
1212
<groupId>br.com.grupo63</groupId>
1313
<artifactId>serviceidentification</artifactId>
14-
<version>4.3.2</version>
14+
<version>5.0.0</version>
1515
<name>Service Identification</name>
16-
<description>FIAP SOAT1 2023 - Group 63 - Phase 4</description>
16+
<description>FIAP SOAT1 2023 - Group 63 - Phase 5</description>
1717
<properties>
1818
<java.version>17</java.version>
1919
<sonar.coverage.exclusions>

src/main/java/br/com/grupo63/serviceidentification/api/controller/client/ClientAPIController.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ClientAPIController extends AbstractAPIController {
2626
summary = "Identificar o cliente (Utilizado pelo Lambda de identificação)",
2727
description = "Recupera o ID do cliente caso ele exista e se não existir já o cria")
2828
@PostMapping("/identification")
29-
public ResponseEntity<ClientControllerDTO> identify(@RequestParam String nationalId) throws NotFoundException {
29+
public ResponseEntity<ClientControllerDTO> identify(@RequestParam String nationalId) {
3030
ClientControllerDTO clientDTO = new ClientControllerDTO(nationalId);
3131
return ResponseEntity.ok(clientController.identify(clientDTO));
3232
}
@@ -35,7 +35,7 @@ public ResponseEntity<ClientControllerDTO> identify(@RequestParam String nationa
3535
summary = "Cria um cliente",
3636
description = "Registra um cliente através de seu CPF")
3737
@PostMapping
38-
public ResponseEntity<ClientControllerDTO> create(@RequestParam String nationalId) throws NotFoundException {
38+
public ResponseEntity<ClientControllerDTO> create(@RequestParam String nationalId) {
3939
ClientControllerDTO clientDTO = new ClientControllerDTO(nationalId);
4040
return ResponseEntity.ok(clientController.create(clientDTO));
4141
}
@@ -68,10 +68,24 @@ public ResponseEntity<ClientControllerDTO> update(@Valid @RequestBody ClientCont
6868
summary = "Excluir cliente",
6969
description = "Exclui um cliente por id")
7070
@DeleteMapping("/{id}")
71-
public ResponseEntity delete(@PathVariable("id") String id) throws NotFoundException {
71+
public ResponseEntity<Void> delete(@PathVariable("id") String id) throws NotFoundException {
7272
clientController.delete(id);
7373
return ResponseEntity.ok().build();
7474
}
7575

76+
@Operation(
77+
tags = "LGPD",
78+
summary = "Exclusão de dados pessoais",
79+
description = "Exclui um cliente por CPF e realiza anonimização dos dados pessoais. Utiliza os dados extras para validar se é o próprio usuário excluindo os dados.")
80+
@DeleteMapping("/delete-personal-data")
81+
public ResponseEntity<Void> deletePersonalData(
82+
@RequestParam String nationalId,
83+
@RequestParam String name,
84+
@RequestParam String address,
85+
@RequestParam String phoneNumber
86+
) throws NotFoundException {
87+
clientController.deletePersonalData(nationalId);
88+
return ResponseEntity.ok().build();
89+
}
7690

7791
}

src/main/java/br/com/grupo63/serviceidentification/controller/ClientController.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public class ClientController {
1717

1818
private final ClientUseCase clientUseCase;
1919

20-
public ClientControllerDTO identify(ClientControllerDTO dto) throws NotFoundException {
20+
public ClientControllerDTO identify(ClientControllerDTO dto) {
2121
Client entity = new Client();
2222
ClientAdapter.fillEntity(dto, entity);
2323
return ClientPresenter.toDto(clientUseCase.identify(entity));
2424
}
2525

26-
public ClientControllerDTO create(ClientControllerDTO dto) throws NotFoundException {
26+
public ClientControllerDTO create(ClientControllerDTO dto) {
2727
Client entity = new Client();
2828
ClientAdapter.fillEntity(dto, entity);
2929
entity = clientUseCase.create(entity);
@@ -50,4 +50,9 @@ public void delete(String id) throws NotFoundException {
5050
Client entity = clientUseCase.read(id);
5151
clientUseCase.delete(entity);
5252
}
53+
54+
public void deletePersonalData(String nationalId) throws NotFoundException {
55+
Client entity = clientUseCase.findByNationalId(nationalId);
56+
clientUseCase.deletePersonalData(entity);
57+
}
5358
}

src/main/java/br/com/grupo63/serviceidentification/entity/client/Client.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public class Client {
1919
public void delete() {
2020
this.deleted = true;
2121
}
22+
2223
}

src/main/java/br/com/grupo63/serviceidentification/gateway/client/entity/ClientPersistenceEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ClientPersistenceEntity {
3131
public ClientPersistenceEntity(Client client) {
3232
this.id = client.getId();
3333
this.nationalId = client.getNationalId();
34+
this.deleted = client.isDeleted();
3435
}
3536

3637
public Client toModel() {

src/main/java/br/com/grupo63/serviceidentification/usecase/client/ClientUseCase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ public void delete(Client client) {
5858
gateway.saveAndFlush(client);
5959
}
6060

61+
@Override
62+
public void deletePersonalData(Client client) {
63+
client.setNationalId("00000000000");
64+
client.delete();
65+
gateway.saveAndFlush(client);
66+
}
67+
6168
}

src/main/java/br/com/grupo63/serviceidentification/usecase/client/IClientUseCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ public interface IClientUseCase {
2121

2222
void delete(Client entity);
2323

24+
void deletePersonalData(Client client);
2425
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Due to how Spring Boot autoconfiguration works, this file needs to exist for the locale files to be detected.

src/test/java/br/com/grupo63/serviceidentification/ClientIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void testDelete_EndToEnd() {
139139
when(clientJpaRepository.findByIdAndDeletedFalse(defaultClientPersistenceEntity.getId())).thenReturn(Optional.of(defaultClientPersistenceEntity));
140140
when(clientJpaRepository.save(any())).thenReturn(new ClientPersistenceEntity(defaultClientPersistenceEntity.getId(), true, defaultClientPersistenceEntity.getNationalId()));
141141

142-
ResponseEntity<DefaultResponseDTO> response = clientAPIController.delete(defaultClientPersistenceEntity.getId());
142+
ResponseEntity<Void> response = clientAPIController.delete(defaultClientPersistenceEntity.getId());
143143

144144
assertEquals(HttpStatus.OK, response.getStatusCode());
145145
assertNull(response.getBody());

0 commit comments

Comments
 (0)