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.otros.ConfirmadoTF;
|
||||||
import com.example.fercoganbackend.service.UsuarioService;
|
import com.example.fercoganbackend.service.UsuarioService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -72,13 +73,12 @@ public class UserController {
|
|||||||
|
|
||||||
// ✅ Eliminar usuario
|
// ✅ Eliminar usuario
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public void eliminarUsuario(@PathVariable Long id) {
|
public ResponseEntity<String> eliminarUsuario(@PathVariable Long id) {
|
||||||
service.getAll().stream()
|
service.eliminarUsuario(id);
|
||||||
.filter(u -> u.getId().equals(id))
|
return ResponseEntity.ok("Usuario eliminado correctamente");
|
||||||
.findFirst()
|
|
||||||
.ifPresent(u -> service.getAll().remove(u)); // eliminaría de lista temporal (idealmente manejarlo con repo.deleteById(id))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ✅ DTO interno para registro
|
// ✅ DTO interno para registro
|
||||||
public static class UsuarioRequest {
|
public static class UsuarioRequest {
|
||||||
private String username;
|
private String username;
|
||||||
|
|||||||
@@ -67,5 +67,12 @@ public class UsuarioService {
|
|||||||
return confirmadotf;
|
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