Skip to content

Commit

Permalink
feat: data exclusion endpoint; fix messages; minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
g-otn committed Mar 10, 2024
1 parent ea8daff commit c8a3d00
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</parent>
<groupId>br.com.grupo63</groupId>
<artifactId>serviceidentification</artifactId>
<version>4.3.2</version>
<version>5.0.0</version>
<name>Service Identification</name>
<description>FIAP SOAT1 2023 - Group 63 - Phase 4</description>
<description>FIAP SOAT1 2023 - Group 63 - Phase 5</description>
<properties>
<java.version>17</java.version>
<sonar.coverage.exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientControllerDTO> identify(@RequestParam String nationalId) throws NotFoundException {
public ResponseEntity<ClientControllerDTO> identify(@RequestParam String nationalId) {
ClientControllerDTO clientDTO = new ClientControllerDTO(nationalId);
return ResponseEntity.ok(clientController.identify(clientDTO));
}
Expand All @@ -35,7 +35,7 @@ public ResponseEntity<ClientControllerDTO> identify(@RequestParam String nationa
summary = "Cria um cliente",
description = "Registra um cliente através de seu CPF")
@PostMapping
public ResponseEntity<ClientControllerDTO> create(@RequestParam String nationalId) throws NotFoundException {
public ResponseEntity<ClientControllerDTO> create(@RequestParam String nationalId) {
ClientControllerDTO clientDTO = new ClientControllerDTO(nationalId);
return ResponseEntity.ok(clientController.create(clientDTO));
}
Expand Down Expand Up @@ -68,10 +68,24 @@ public ResponseEntity<ClientControllerDTO> 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<Void> 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<Void> deletePersonalData(
@RequestParam String nationalId,
@RequestParam String name,
@RequestParam String address,
@RequestParam String phoneNumber
) throws NotFoundException {
clientController.deletePersonalData(nationalId);
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class Client {
public void delete() {
this.deleted = true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public interface IClientUseCase {

void delete(Client entity);

void deletePersonalData(Client client);
}
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Due to how Spring Boot autoconfiguration works, this file needs to exist for the locale files to be detected.

0 comments on commit c8a3d00

Please sign in to comment.