API REST robusta para la gestión de bibliotecas digitales, desarrollada con Spring Boot 3.3 y PostgreSQL.
Incluye autenticación JWT, roles, validación avanzada, búsqueda combinada, manejo global de excepciones y documentación con Swagger/OpenAPI.
- 🔐 Autenticación JWT con Spring Security 6
- 📚 CRUD completo para libros, autores, categorías y reseñas
- 🧭 Búsqueda avanzada con filtros combinados
- 🧩 Sistema de roles (
USER,ADMIN) - ✅ Validación de datos con Bean Validation
⚠️ Manejo global de excepciones- 📖 Documentación API con Swagger/OpenAPI
- 🧪 Tests unitarios e integración (JUnit 5 + Mockito)
- 🗄️ Base de datos PostgreSQL en Supabase
| Tecnología | Descripción |
|---|---|
| Backend | Spring Boot 3.3 |
| Java | 17 |
| Database | PostgreSQL (Supabase) |
| Security | Spring Security 6 + JWT |
| ORM | Spring Data JPA + Hibernate |
| Build Tool | Maven |
| Testing | JUnit 5 + Mockito |
| Docs | Swagger/OpenAPI 3 |
- ☕ JDK 17 o superior
- 🧱 Maven 3.6+
- 🗃️ Cuenta en Supabase o base PostgreSQL local
- 💻 IDE (IntelliJ IDEA, Eclipse, VS Code, Cursor)
git clone https://github.com/LOAD-13/REST-API-Library-Management.git
cd library-management-api- Crea un nuevo proyecto en Supabase
- Ve a Settings → Database y copia tus credenciales
- Crea un archivo
.enven la raíz del proyecto:
DB_URL=jdbc:postgresql://db.tu-proyecto.supabase.co:5432/postgres
DB_USERNAME=postgres
DB_PASSWORD=tu_password_supabase
JWT_SECRET=dGVzdF9zZWNyZXRfa2V5X2Zvcl9qd3RfYXV0aGVudGljYXRpb25fMjU2X2JpdHNfbG9uZw==
JWT_EXPIRATION=86400000mvn clean installmvn spring-boot:runLa API estará disponible en:
👉 http://localhost:8080
Swagger UI:
🔗 http://localhost:8080/swagger-ui.html
📚 Ver Documentación Interactiva (Swagger UI)**
| Método | Endpoint | Descripción |
|---|---|---|
POST |
/api/auth/register |
Registrar usuario |
POST |
/api/auth/login |
Iniciar sesión (obtener JWT) |
| Método | Endpoint | Descripción |
|---|---|---|
GET |
/api/books |
Listar libros (paginado) |
GET |
/api/books/{id} |
Obtener libro por ID |
POST |
/api/books |
Crear libro (ADMIN) |
PUT |
/api/books/{id} |
Actualizar libro (ADMIN) |
DELETE |
/api/books/{id} |
Eliminar libro (ADMIN) |
GET |
/api/books/search |
Búsqueda simple |
GET |
/api/books/advanced-search |
Búsqueda avanzada |
| Método | Endpoint | Descripción |
|---|---|---|
GET |
/api/authors |
Listar autores |
POST |
/api/authors |
Crear autor (ADMIN) |
PUT |
/api/authors/{id} |
Actualizar autor (ADMIN) |
DELETE |
/api/authors/{id} |
Eliminar autor (ADMIN) |
| Método | Endpoint | Descripción |
|---|---|---|
GET |
/api/categories |
Listar categorías |
POST |
/api/categories |
Crear categoría (ADMIN) |
| Método | Endpoint | Descripción |
|---|---|---|
GET |
/api/reviews/book/{bookId} |
Listar reseñas de un libro |
POST |
/api/reviews |
Crear reseña (autenticado) |
PUT |
/api/reviews/{id} |
Actualizar reseña propia |
DELETE |
/api/reviews/{id} |
Eliminar reseña propia |
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"email": "admin@example.com",
"password": "admin123"
}'curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "admin123"
}'📦 Respuesta:
{
"token": "eyJhbGciOiJIUzI1NiJ9...",
"type": "Bearer",
"id": 1,
"username": "admin",
"email": "admin@example.com",
"role": "USER"
}curl -X POST http://localhost:8080/api/books \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <tu-token>" \
-d '{
"title": "Cien Años de Soledad",
"isbn": "978-0307474728",
"description": "Una obra maestra",
"publicationDate": "1967-05-30",
"authorIds": [1],
"categoryIds": [2]
}'# Ejecutar todos los tests
mvn test
# Ejecutar tests con reporte de cobertura
mvn test jacoco:report
# Tests de integración
mvn verifylibrary-management-api/
├── src/
│ ├── main/
│ │ ├── java/com/tudominio/library/
│ │ │ ├── config/ # Configuración (Security, Swagger)
│ │ │ ├── controller/ # Controladores REST
│ │ │ ├── dto/ # DTOs (Request/Response)
│ │ │ ├── entity/ # Entidades JPA
│ │ │ ├── exception/ # Excepciones personalizadas
│ │ │ ├── repository/ # Repositorios JPA
│ │ │ ├── service/ # Lógica de negocio
│ │ │ ├── specification/ # Specifications JPA
│ │ │ └── util/ # Utilidades y mappers
│ │ └── resources/
│ │ └── application.properties
│ └── test/
│ └── java/com/tudominio/library/
│ ├── controller/ # Tests de controladores
│ ├── service/ # Tests de servicios
│ └── repository/ # Tests de repositorios
└── pom.xml
graph TD
A[Cliente / Frontend] -->|HTTP| B[Spring Boot API]
B --> C[Controladores]
C --> D[Servicios]
D --> E[Repositorios]
E --> F[(PostgreSQL / Supabase)]
mvn clean package -DskipTestsjava -jar target/library-management-api-1.0.0.jar- Configura las variables de entorno en tu servicio
- Agrega un archivo
system.properties:
java.runtime.version=17El servicio detectará automáticamente el pom.xml y ejecutará la aplicación.
Si deseas un usuario administrador desde el inicio, puedes crearlo directamente en Supabase:
INSERT INTO users (username, email, password, role, created_at, updated_at)
VALUES (
'admin',
'admin@library.com',
'$2a$10$XptfskLsT7h3KqP8cB.7JO5dXK3WNJp5rJ8jWjq3j3qHgXqkJvqF2', -- password: admin123
'ADMIN',
NOW(),
NOW()
);# Iniciar el proyecto
mvn spring-boot:run
# Compilar cambios
mvn clean compile
# Ejecutar tests
mvn test
# Ver documentación
# Abrir: http://localhost:8080/swagger-ui.html- Dockerización completa del entorno
- Sistema de préstamos y devoluciones
- Integración con servicio de correo para notificaciones
- Búsqueda semántica con Elasticsearch
- Frontend en React o Angular
Joaquín Loa Denegri
- GitHub: @LOAD-13
- Proyecto: REST API Library Management
Las contribuciones son bienvenidas 🙌
Por favor, abre un issue antes de realizar un pull request para discutir los cambios propuestos.
Si te gustó este proyecto, considera darle una estrella en GitHub!
Tu apoyo ayuda a impulsar el desarrollo de más proyectos como este.
Este proyecto está bajo la MIT License.
MIT License
Copyright (c) 2025 Joaquín Loa Denegri
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Hecho con ❤️ por Joaquín Loa Denegri