creamos: delete usuario
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -5,6 +5,7 @@ import com.example.fercoganbackend.entity.Usuario;
|
||||
import com.example.fercoganbackend.otros.ConfirmadoTF;
|
||||
import com.example.fercoganbackend.service.UsuarioService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -72,13 +73,12 @@ public class UserController {
|
||||
|
||||
// ✅ Eliminar usuario
|
||||
@DeleteMapping("/{id}")
|
||||
public void eliminarUsuario(@PathVariable Long id) {
|
||||
service.getAll().stream()
|
||||
.filter(u -> u.getId().equals(id))
|
||||
.findFirst()
|
||||
.ifPresent(u -> service.getAll().remove(u)); // eliminaría de lista temporal (idealmente manejarlo con repo.deleteById(id))
|
||||
public ResponseEntity<String> eliminarUsuario(@PathVariable Long id) {
|
||||
service.eliminarUsuario(id);
|
||||
return ResponseEntity.ok("Usuario eliminado correctamente");
|
||||
}
|
||||
|
||||
|
||||
// ✅ DTO interno para registro
|
||||
public static class UsuarioRequest {
|
||||
private String username;
|
||||
|
||||
@@ -67,5 +67,12 @@ public class UsuarioService {
|
||||
return confirmadotf;
|
||||
}
|
||||
|
||||
public void eliminarUsuario(Long id) {
|
||||
if (!repo.existsById(id)) {
|
||||
throw new RuntimeException("Usuario no encontrado");
|
||||
}
|
||||
repo.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user