From fe7f2a934a1cb24ed0a72e9ae5d539cc480f97c0 Mon Sep 17 00:00:00 2001 From: andre00bejarano00vaca Date: Fri, 10 Oct 2025 15:18:09 -0400 Subject: [PATCH] creamos: delete usuario --- .../fercoganbackend/controller/UserController.java | 10 +++++----- .../fercoganbackend/service/UsuarioService.java | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/fercoganbackend/controller/UserController.java b/src/main/java/com/example/fercoganbackend/controller/UserController.java index 6e03992..9bd9151 100644 --- a/src/main/java/com/example/fercoganbackend/controller/UserController.java +++ b/src/main/java/com/example/fercoganbackend/controller/UserController.java @@ -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 eliminarUsuario(@PathVariable Long id) { + service.eliminarUsuario(id); + return ResponseEntity.ok("Usuario eliminado correctamente"); } + // ✅ DTO interno para registro public static class UsuarioRequest { private String username; diff --git a/src/main/java/com/example/fercoganbackend/service/UsuarioService.java b/src/main/java/com/example/fercoganbackend/service/UsuarioService.java index e8092c4..2b685ad 100644 --- a/src/main/java/com/example/fercoganbackend/service/UsuarioService.java +++ b/src/main/java/com/example/fercoganbackend/service/UsuarioService.java @@ -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); + } + }