0
Good afternoon, you guys.
I’m having difficulties to implement my Register on Spring Boot. I’m willing to do the method in three ways(if,else if,else
) that if it is all right to register, that if anyone already exists with that email then from "Existing" and any error is "Invalid". But it is not working, the method I did to see if there is already in the bank the Person I am registering this correct? Someone can help me as I post and if the code is right or if there is some way to improve. Thank you.
Repository
.
String findByEmail(String email)
------
Controller.
@PostMapping
public ResponseEntity<Pessoa> cadastrar(@RequestBody Pessoa p) {
if(p.getEmail() == repository.findByEmail(p.getEmail())){
return ResponseEntity.status(400).build();
}else if(p != null) {
return ResponseEntity.ok().body(repository.save(p));
}else {
return ResponseEntity.badRequest().build();
}
}
When you say it’s not working you need to be clearer, what’s not working ? the validation ? some error is being spit out ? what the behaviour of the request is ?
– Isaías de Lima Coelho
I see you didn’t call anything to register
– nullptr
@Isaíasdelimacoelho when I register an email with one that already exists in the table database Pessoa it adds the same way and I do not want it, and I wanted to know how to add some message like "Successfully registered" "Existing" "Invalid "
– Leonardo
@nullptr arranged !
– Leonardo
@Isaíasdelimacoelho I am using the Postman to make the requisitions, I wanted that in the Response came this message you know? And do you have any tips to improve this code? I’m finding it very pig.
– Leonardo