Skip to content

Commit

Permalink
feat: creating a little validation before delete one consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroVidalDev committed Jun 12, 2024
1 parent fde6f21 commit b4a5d96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/pedro/sphynx/domain/ConsumerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit b4a5d96

Please sign in to comment.