From b4a5d9688b98d1b14a4bf70386e3e734af17667d Mon Sep 17 00:00:00 2001 From: PedroVidalDev Date: Wed, 12 Jun 2024 16:13:49 -0300 Subject: [PATCH] feat: creating a little validation before delete one consumer --- .../application/controller/ConsumerController.java | 5 +++-- .../java/com/pedro/sphynx/domain/ConsumerService.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/pedro/sphynx/application/controller/ConsumerController.java b/src/main/java/com/pedro/sphynx/application/controller/ConsumerController.java index 6a592f4..33af327 100644 --- a/src/main/java/com/pedro/sphynx/application/controller/ConsumerController.java +++ b/src/main/java/com/pedro/sphynx/application/controller/ConsumerController.java @@ -6,6 +6,7 @@ import com.pedro.sphynx.application.dtos.message.MessageDTO; import com.pedro.sphynx.domain.ConsumerService; import com.pedro.sphynx.domain.MessageService; +import com.pedro.sphynx.infrastructure.exceptions.Validation; import com.pedro.sphynx.infrastructure.repository.ConsumerRepository; import jakarta.validation.Valid; import lombok.Builder; @@ -51,8 +52,8 @@ public ResponseEntity update(@PathVariable String ra, @RequestBody @Valid Consum @DeleteMapping("/{ra}") @Transactional - public ResponseEntity delete(@PathVariable String ra){ - repository.deleteByRa(ra); + public ResponseEntity delete(@PathVariable String ra, @RequestHeader("Language") String language){ + service.deleteVerify(ra, language); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/com/pedro/sphynx/domain/ConsumerService.java b/src/main/java/com/pedro/sphynx/domain/ConsumerService.java index 1f48e1b..0486145 100644 --- a/src/main/java/com/pedro/sphynx/domain/ConsumerService.java +++ b/src/main/java/com/pedro/sphynx/domain/ConsumerService.java @@ -55,4 +55,15 @@ public ConsumerDataComplete updateVerify(ConsumerDataEditInput data, String ra, throw new Validation(messages.getString("error.raDontExists")); } } + + public void deleteVerify(String ra, String language){ + ResourceBundle messages = defineMessagesLanguage(language); + + if(!consumerRepository.existsByRa(ra)){ + throw new Validation(messages.getString("error.raDontExists")); + } + else{ + consumerRepository.deleteByRa(ra); + } + } }