From c8a3d00fc0d3f3a25076b4a6ccb473d7d8f1deae Mon Sep 17 00:00:00 2001
From: g-otn <44736064+g-otn@users.noreply.github.com>
Date: Sun, 10 Mar 2024 01:43:05 -0300
Subject: [PATCH] feat: data exclusion endpoint; fix messages; minor
improvements
---
pom.xml | 4 ++--
.../client/ClientAPIController.java | 20 ++++++++++++++++---
.../controller/ClientController.java | 9 +++++++--
.../entity/client/Client.java | 1 +
.../entity/ClientPersistenceEntity.java | 1 +
.../usecase/client/ClientUseCase.java | 7 +++++++
.../usecase/client/IClientUseCase.java | 1 +
src/main/resources/messages.properties | 1 +
8 files changed, 37 insertions(+), 7 deletions(-)
create mode 100644 src/main/resources/messages.properties
diff --git a/pom.xml b/pom.xml
index 4030a18..9500ff8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,9 +11,9 @@
br.com.grupo63
serviceidentification
- 4.3.2
+ 5.0.0
Service Identification
- FIAP SOAT1 2023 - Group 63 - Phase 4
+ FIAP SOAT1 2023 - Group 63 - Phase 5
17
diff --git a/src/main/java/br/com/grupo63/serviceidentification/api/controller/client/ClientAPIController.java b/src/main/java/br/com/grupo63/serviceidentification/api/controller/client/ClientAPIController.java
index 4f0b02f..55f179a 100644
--- a/src/main/java/br/com/grupo63/serviceidentification/api/controller/client/ClientAPIController.java
+++ b/src/main/java/br/com/grupo63/serviceidentification/api/controller/client/ClientAPIController.java
@@ -26,7 +26,7 @@ public class ClientAPIController extends AbstractAPIController {
summary = "Identificar o cliente (Utilizado pelo Lambda de identificação)",
description = "Recupera o ID do cliente caso ele exista e se não existir já o cria")
@PostMapping("/identification")
- public ResponseEntity identify(@RequestParam String nationalId) throws NotFoundException {
+ public ResponseEntity identify(@RequestParam String nationalId) {
ClientControllerDTO clientDTO = new ClientControllerDTO(nationalId);
return ResponseEntity.ok(clientController.identify(clientDTO));
}
@@ -35,7 +35,7 @@ public ResponseEntity identify(@RequestParam String nationa
summary = "Cria um cliente",
description = "Registra um cliente através de seu CPF")
@PostMapping
- public ResponseEntity create(@RequestParam String nationalId) throws NotFoundException {
+ public ResponseEntity create(@RequestParam String nationalId) {
ClientControllerDTO clientDTO = new ClientControllerDTO(nationalId);
return ResponseEntity.ok(clientController.create(clientDTO));
}
@@ -68,10 +68,24 @@ public ResponseEntity update(@Valid @RequestBody ClientCont
summary = "Excluir cliente",
description = "Exclui um cliente por id")
@DeleteMapping("/{id}")
- public ResponseEntity delete(@PathVariable("id") String id) throws NotFoundException {
+ public ResponseEntity delete(@PathVariable("id") String id) throws NotFoundException {
clientController.delete(id);
return ResponseEntity.ok().build();
}
+ @Operation(
+ tags = "LGPD",
+ summary = "Exclusão de dados pessoais",
+ 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.")
+ @DeleteMapping("/delete-personal-data")
+ public ResponseEntity deletePersonalData(
+ @RequestParam String nationalId,
+ @RequestParam String name,
+ @RequestParam String address,
+ @RequestParam String phoneNumber
+ ) throws NotFoundException {
+ clientController.deletePersonalData(nationalId);
+ return ResponseEntity.ok().build();
+ }
}
diff --git a/src/main/java/br/com/grupo63/serviceidentification/controller/ClientController.java b/src/main/java/br/com/grupo63/serviceidentification/controller/ClientController.java
index e44a5c7..0050e8a 100644
--- a/src/main/java/br/com/grupo63/serviceidentification/controller/ClientController.java
+++ b/src/main/java/br/com/grupo63/serviceidentification/controller/ClientController.java
@@ -17,13 +17,13 @@ public class ClientController {
private final ClientUseCase clientUseCase;
- public ClientControllerDTO identify(ClientControllerDTO dto) throws NotFoundException {
+ public ClientControllerDTO identify(ClientControllerDTO dto) {
Client entity = new Client();
ClientAdapter.fillEntity(dto, entity);
return ClientPresenter.toDto(clientUseCase.identify(entity));
}
- public ClientControllerDTO create(ClientControllerDTO dto) throws NotFoundException {
+ public ClientControllerDTO create(ClientControllerDTO dto) {
Client entity = new Client();
ClientAdapter.fillEntity(dto, entity);
entity = clientUseCase.create(entity);
@@ -50,4 +50,9 @@ public void delete(String id) throws NotFoundException {
Client entity = clientUseCase.read(id);
clientUseCase.delete(entity);
}
+
+ public void deletePersonalData(String nationalId) throws NotFoundException {
+ Client entity = clientUseCase.findByNationalId(nationalId);
+ clientUseCase.deletePersonalData(entity);
+ }
}
diff --git a/src/main/java/br/com/grupo63/serviceidentification/entity/client/Client.java b/src/main/java/br/com/grupo63/serviceidentification/entity/client/Client.java
index 717344e..fb31027 100644
--- a/src/main/java/br/com/grupo63/serviceidentification/entity/client/Client.java
+++ b/src/main/java/br/com/grupo63/serviceidentification/entity/client/Client.java
@@ -19,4 +19,5 @@ public class Client {
public void delete() {
this.deleted = true;
}
+
}
diff --git a/src/main/java/br/com/grupo63/serviceidentification/gateway/client/entity/ClientPersistenceEntity.java b/src/main/java/br/com/grupo63/serviceidentification/gateway/client/entity/ClientPersistenceEntity.java
index 1e485e6..bb84e0c 100644
--- a/src/main/java/br/com/grupo63/serviceidentification/gateway/client/entity/ClientPersistenceEntity.java
+++ b/src/main/java/br/com/grupo63/serviceidentification/gateway/client/entity/ClientPersistenceEntity.java
@@ -31,6 +31,7 @@ public class ClientPersistenceEntity {
public ClientPersistenceEntity(Client client) {
this.id = client.getId();
this.nationalId = client.getNationalId();
+ this.deleted = client.isDeleted();
}
public Client toModel() {
diff --git a/src/main/java/br/com/grupo63/serviceidentification/usecase/client/ClientUseCase.java b/src/main/java/br/com/grupo63/serviceidentification/usecase/client/ClientUseCase.java
index 6dcc1f9..988e40d 100644
--- a/src/main/java/br/com/grupo63/serviceidentification/usecase/client/ClientUseCase.java
+++ b/src/main/java/br/com/grupo63/serviceidentification/usecase/client/ClientUseCase.java
@@ -58,4 +58,11 @@ public void delete(Client client) {
gateway.saveAndFlush(client);
}
+ @Override
+ public void deletePersonalData(Client client) {
+ client.setNationalId("00000000000");
+ client.delete();
+ gateway.saveAndFlush(client);
+ }
+
}
diff --git a/src/main/java/br/com/grupo63/serviceidentification/usecase/client/IClientUseCase.java b/src/main/java/br/com/grupo63/serviceidentification/usecase/client/IClientUseCase.java
index f40742d..8b2618d 100644
--- a/src/main/java/br/com/grupo63/serviceidentification/usecase/client/IClientUseCase.java
+++ b/src/main/java/br/com/grupo63/serviceidentification/usecase/client/IClientUseCase.java
@@ -21,4 +21,5 @@ public interface IClientUseCase {
void delete(Client entity);
+ void deletePersonalData(Client client);
}
diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties
new file mode 100644
index 0000000..afd6307
--- /dev/null
+++ b/src/main/resources/messages.properties
@@ -0,0 +1 @@
+# Due to how Spring Boot autoconfiguration works, this file needs to exist for the locale files to be detected.