From 0b9407f3f933292479709f0e931a9731f27beb38 Mon Sep 17 00:00:00 2001 From: CarmenGlez20 Date: Fri, 22 May 2026 18:05:33 -0600 Subject: [PATCH] feat: notificaction service completo --- notification-service/main.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/notification-service/main.py b/notification-service/main.py index a5c9f44..3f2bdb7 100644 --- a/notification-service/main.py +++ b/notification-service/main.py @@ -246,4 +246,31 @@ def startup(): # Arranca el cron en background t = threading.Thread(target=start_cron, daemon=True) t.start() - print(f"[STARTUP] Notification Service listo. {len(RUTAS)} rutas cargadas.") \ No newline at end of file + print(f"[STARTUP] Notification Service listo. {len(RUTAS)} rutas cargadas.") + +@app.post("/internal/reset") +def reset_routes(): + """Reinicia todas las rutas a positionId 1. Útil para el demo.""" + for route_id in RUTAS: + route_state[route_id] = {"positionId": 1, "notified": set()} + print("[RESET] Todas las rutas reiniciadas a positionId 1") + return {"status": "ok", "message": f"{len(RUTAS)} rutas reiniciadas"} + +@app.post("/internal/demo") +def demo_trigger(payload: dict): + """ + Fuerza una ruta a un positionId específico al instante. + Ideal para demos en vivo. + Body: { "routeId": "RUTA-01", "positionId": 4 } + """ + route_id = payload.get("routeId", "RUTA-01") + position_id = payload.get("positionId", 4) + + # Limpia notificaciones previas para que dispare de nuevo + state = route_state.setdefault(route_id, {"positionId": 1, "notified": set()}) + state["notified"].discard("ROUTE_START") + state["notified"].discard("TRUCK_PROXIMITY") + state["notified"].discard("ROUTE_COMPLETED") + + process_position_update(route_id, position_id) + return {"status": "ok", "routeId": route_id, "positionId": position_id} \ No newline at end of file