buscar usuario por id
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled

This commit is contained in:
2025-12-10 16:11:31 -04:00
parent 9abd4cce72
commit cb32994d9b
3 changed files with 16 additions and 1 deletions

View File

@@ -78,6 +78,12 @@ public class UserController {
return ResponseEntity.ok("Usuario eliminado correctamente"); return ResponseEntity.ok("Usuario eliminado correctamente");
} }
@GetMapping("/id/{username}")
public ResponseEntity<Long> getIdPorUsername(@PathVariable String username) {
Long id = service.findId(username);
return ResponseEntity.ok(id);
}
// ✅ DTO interno para registro // ✅ DTO interno para registro
public static class UsuarioRequest { public static class UsuarioRequest {

View File

@@ -74,5 +74,14 @@ public class UsuarioService {
repo.deleteById(id); repo.deleteById(id);
} }
//encontrar el usuario por gmail
public Long findId(String username){
Usuario usuario = repo.findByUsername(username)
.orElseThrow(() -> new RuntimeException("Usuario no encontrado: " + username));
return usuario.getId();
}
} }

View File

@@ -1,5 +1,5 @@
spring.application.name=fercoganbackend spring.application.name=fercoganbackend
spring.profiles.active=prod spring.profiles.active=dev
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update