241
QUICKSTART_NOTIFICATIONS.md
Normal file
241
QUICKSTART_NOTIFICATIONS.md
Normal file
@@ -0,0 +1,241 @@
|
||||
# Quick Start: API de Notificaciones
|
||||
|
||||
## 🚀 Inicio Rápido
|
||||
|
||||
### Requisitos Previos
|
||||
- Docker y Docker Compose instalados
|
||||
- Python 3.10+ (si ejecutar sin Docker)
|
||||
- Proyecto VoxPopuli clonado
|
||||
|
||||
---
|
||||
|
||||
## 📦 Opción 1: Con Docker Compose (Recomendado)
|
||||
|
||||
### 1. Levantar todos los servicios
|
||||
```bash
|
||||
cd c:\Users\Rodo Machenike\Documents\API\VoxPopuli
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### 2. Verificar que todo está corriendo
|
||||
```bash
|
||||
docker-compose ps
|
||||
```
|
||||
|
||||
Deberías ver:
|
||||
- voxpopuli_mysql (3306)
|
||||
- voxpopuli_mongo (27017)
|
||||
- voxpopuli_rabbitmq (5672, 15672)
|
||||
|
||||
### 3. Levantar la aplicación Python
|
||||
```bash
|
||||
# Crear entorno virtual si no existe
|
||||
python -m venv venv
|
||||
|
||||
# Activar entorno virtual
|
||||
# En Windows:
|
||||
venv\Scripts\activate
|
||||
# En Linux/Mac:
|
||||
source venv/bin/activate
|
||||
|
||||
# Instalar dependencias
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Ejecutar la aplicación
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
### 4. Verificar que APIs están funcionando
|
||||
```bash
|
||||
# Terminal nueva
|
||||
curl http://localhost:8000/ # Usuarios
|
||||
curl http://localhost:8001/ # Reportes
|
||||
curl http://localhost:8002/ # Notificaciones (NUEVA)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ Verificar Conexión a RabbitMQ
|
||||
|
||||
### Acceder al Dashboard de RabbitMQ
|
||||
1. Ir a: http://localhost:15672
|
||||
2. Usuario: `voxpopuli`
|
||||
3. Contraseña: `voxpopuli_pass`
|
||||
|
||||
### Ver colas
|
||||
- Queues > `reports_queue` - Para eventos de reportes
|
||||
- Queues > `notifications_queue` - Para eventos de notificaciones (NUEVA)
|
||||
- Queues > `users_queue` - Para eventos de usuarios
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Prueba Rápida del Flujo Completo
|
||||
|
||||
### 1. Crear un usuario
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/users/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"nombre": "Juan",
|
||||
"apellido": "Pérez",
|
||||
"email": "juan@example.com",
|
||||
"contraseña": "password123",
|
||||
"fecha_nacimiento": "1990-01-15"
|
||||
}'
|
||||
```
|
||||
|
||||
Guardar el `user_id` que retorna (ej: 1)
|
||||
|
||||
### 2. Login para obtener token JWT
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/login \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"email": "juan@example.com",
|
||||
"contraseña": "password123"
|
||||
}'
|
||||
```
|
||||
|
||||
Guardar el `access_token` que retorna
|
||||
|
||||
### 3. Crear un reporte
|
||||
```bash
|
||||
curl -X POST http://localhost:8001/reports/ \
|
||||
-H "Authorization: Bearer {access_token}" \
|
||||
-F "id_usuario=1" \
|
||||
-F "tipo_reporte=1" \
|
||||
-F "descripcion=Calle rota en la esquina" \
|
||||
-F "ubicacion=Calle 5 y Carrera 10"
|
||||
```
|
||||
|
||||
Guardar el `id_reporte` que retorna
|
||||
|
||||
### 4. Cambiar estado del reporte (Dispara Notificación)
|
||||
```bash
|
||||
curl -X PUT http://localhost:8001/reports/{id_reporte}/status \
|
||||
-H "Authorization: Bearer {access_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"estado": "resuelto"}'
|
||||
```
|
||||
|
||||
### 5. Verificar que notificación se creó
|
||||
```bash
|
||||
curl http://localhost:8002/notifications/1 \
|
||||
-H "Authorization: Bearer {access_token}"
|
||||
```
|
||||
|
||||
**Resultado esperado:**
|
||||
```json
|
||||
{
|
||||
"total": 1,
|
||||
"unread_count": 1,
|
||||
"notifications": [
|
||||
{
|
||||
"id_notificacion": "...",
|
||||
"id_usuario": 1,
|
||||
"id_reporte": "...",
|
||||
"message": "¡Tu reporte ha sido resuelto!",
|
||||
"fecha": "2024-04-29T...",
|
||||
"read": false
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 6. Marcar como leída
|
||||
```bash
|
||||
curl -X PUT http://localhost:8002/notifications/{notification_id}/read \
|
||||
-H "Authorization: Bearer {access_token}"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 Verificar en Bases de Datos
|
||||
|
||||
### MongoDB - Ver notificación creada
|
||||
```bash
|
||||
# Conectar a MongoDB
|
||||
docker exec -it voxpopuli_mongo mongosh
|
||||
|
||||
# En la terminal de MongoDB:
|
||||
use voxpopuli_notifications
|
||||
db.notificaciones.find()
|
||||
```
|
||||
|
||||
### RabbitMQ - Ver evento enviado
|
||||
1. Ir a http://localhost:15672
|
||||
2. Queues > `notifications_queue`
|
||||
3. Debería mostrar mensajes procesados
|
||||
|
||||
---
|
||||
|
||||
## 📝 Logs en Tiempo Real
|
||||
|
||||
### Ver logs del contenedor de la app
|
||||
```bash
|
||||
# Si ejecutas en Docker
|
||||
docker-compose logs -f
|
||||
|
||||
# Si ejecutas Python directamente
|
||||
# Los logs aparecen en la terminal donde ejecutaste python src/main.py
|
||||
```
|
||||
|
||||
### Buscar errores de notificaciones
|
||||
```bash
|
||||
docker-compose logs -f notifications-consumer # Si estuviera en Docker
|
||||
# O en los logs de Python cuando ejecutas src/main.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Solución de Problemas Rápida
|
||||
|
||||
| Problema | Solución |
|
||||
|----------|----------|
|
||||
| Error de conexión a MongoDB | `docker-compose up -d mongodb && docker-compose logs mongodb` |
|
||||
| Error de conexión a RabbitMQ | `docker-compose up -d rabbitmq && docker-compose logs rabbitmq` |
|
||||
| Notificaciones no se crean | Verificar que `notification_consumer.py` está ejecutando (ver logs) |
|
||||
| Token expirado | Crear nuevo token con login |
|
||||
| No aparecen notificaciones | Verificar `unread_count` primero con `/notifications/{user_id}/unread-count` |
|
||||
|
||||
---
|
||||
|
||||
## 📚 Documentos Disponibles
|
||||
|
||||
1. **IMPLEMENTATION_SUMMARY.md** - Descripción completa de cambios
|
||||
2. **FRONTEND_NOTIFICATIONS_IMPLEMENTATION.md** - Guía para implementar frontend
|
||||
3. **API_EXAMPLES.json** - Ejemplos de requests (actualizado con notificaciones)
|
||||
4. **docker-compose.yaml** - Servicios disponibles
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Próximos Pasos
|
||||
|
||||
1. ✅ Backend: Servicios levantados
|
||||
2. ⬜ Frontend: Implementar según `FRONTEND_NOTIFICATIONS_IMPLEMENTATION.md`
|
||||
3. ⬜ Testing: Pruebas unitarias e integración
|
||||
4. ⬜ Producción: Deploy en servidor
|
||||
|
||||
---
|
||||
|
||||
## 💡 Tips Útiles
|
||||
|
||||
- **Debugging RabbitMQ:** Acceder a http://localhost:15672 para ver estado de colas
|
||||
- **Debugging MongoDB:** Usar MongoDB Compass (herramienta GUI)
|
||||
- **Debugging API:** Usar Swagger UI en http://localhost:8002/docs
|
||||
- **Health Check:** GET http://localhost:8002/ para verificar que la API está viva
|
||||
|
||||
---
|
||||
|
||||
## 📞 Contacto
|
||||
|
||||
Si hay dudas o errores:
|
||||
1. Revisar logs: `docker-compose logs -f`
|
||||
2. Revisar documentación en `IMPLEMENTATION_SUMMARY.md`
|
||||
3. Verificar endpoints en http://localhost:8002/docs
|
||||
|
||||
---
|
||||
|
||||
**¡Todo listo! 🚀**
|
||||
|
||||
La API de Notificaciones está lista para usar.
|
||||
Reference in New Issue
Block a user