feat: Fix nutrition service and add location-based alerts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Changes: - Fix nutrition service: add is_active column and Pydantic validation for UUID/datetime - Add location-based alerts feature: users can now see alerts within 1km radius - Fix CORS and response serialization in nutrition service - Add getCurrentLocation() and loadAlertsNearby() functions - Improve UI for nearby alerts display with distance and response count
This commit is contained in:
@@ -349,6 +349,43 @@ async def health_check():
|
||||
return {"status": "healthy", "service": "emergency_service"}
|
||||
|
||||
|
||||
@app.get("/alerts")
|
||||
async def get_alerts_public(db: AsyncSession = Depends(get_db)):
|
||||
"""Get all emergency alerts (public endpoint for testing)"""
|
||||
result = await db.execute(
|
||||
select(EmergencyAlert)
|
||||
.order_by(EmergencyAlert.created_at.desc())
|
||||
.limit(50)
|
||||
)
|
||||
alerts = result.scalars().all()
|
||||
return [EmergencyAlertResponse.model_validate(alert) for alert in alerts]
|
||||
|
||||
|
||||
@app.post("/alerts")
|
||||
async def create_alert_public(
|
||||
alert_data: dict,
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""Create emergency alert (public endpoint for testing)"""
|
||||
try:
|
||||
new_alert = EmergencyAlert(
|
||||
user_id=alert_data.get("user_id", 1),
|
||||
alert_type=alert_data.get("alert_type", "medical"),
|
||||
latitude=alert_data.get("latitude", 0),
|
||||
longitude=alert_data.get("longitude", 0),
|
||||
title=alert_data.get("title", "Emergency Alert"),
|
||||
description=alert_data.get("description", ""),
|
||||
is_resolved=False
|
||||
)
|
||||
db.add(new_alert)
|
||||
await db.commit()
|
||||
await db.refresh(new_alert)
|
||||
return {"status": "success", "alert_id": new_alert.id}
|
||||
except Exception as e:
|
||||
await db.rollback()
|
||||
return {"status": "error", "detail": str(e)}
|
||||
|
||||
|
||||
@app.websocket("/api/v1/emergency/ws/{user_id}")
|
||||
async def websocket_endpoint(websocket: WebSocket, user_id: str):
|
||||
"""WebSocket endpoint for emergency notifications"""
|
||||
|
||||
Reference in New Issue
Block a user