I am developing a Rest API and I need to validate that the client already exists at the time of registration, using the CPF as the key.
This is my Post method on the controller:
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<Client> save(@Valid @RequestBody Client client) {
return ResponseEntity.ok(this.clientService.save(client));
}
This is my Client class:
@Document
@Data
@AllArgsConstructor
public class Client{
@Id
private String id;
@NotEmpty(message = "Name cannot be empty")
private String name;
@CPF
@Size(min = 0, max = 11)
private String cpf;
I have no idea how to perform the validation on my controller.
Thanks in advance.