I'm making a API REST using Java Spring Boot.
One of my services is deleteUser. that delete User by an Id.
userService.java:
public boolean deleteUser(Long id) { try { usuarioRepository.deleteById(id); return true; } catch(Exception err) { return false; } }
I use try catch to manage the exception in case the Id dont exists or is null, but this never happens
Even If i Post id=24535253 its always true.
userController.java
`@DeleteMapping( path = "/{id}")
public String eliminarPorId(@PathVariable("id") Long id){
boolean ok = this.usuarioService.deleteUser(id);
System.out.println("booleando de id: "+ ok);
if(ok){
return "Se eliminó el usuario con id " + id;
}else{
return "No pudo eliminar el usuario con id" + id;
}
}`
I'm using JDK 17