Start fixing forecast service 15

This commit is contained in:
Urtzi Alfaro
2025-07-30 00:23:05 +02:00
parent 2d1ce2d523
commit 1d05e125a5
5 changed files with 677 additions and 382 deletions

View File

@@ -9,7 +9,8 @@ from uuid import UUID
from app.schemas.external import (
WeatherDataResponse,
WeatherForecastResponse
WeatherForecastResponse,
WeatherForecastRequest
)
from app.services.weather_service import WeatherService
from app.services.messaging import publish_weather_updated
@@ -74,21 +75,19 @@ async def get_current_weather(
@router.post("/tenants/{tenant_id}/weather/forecast", response_model=List[WeatherForecastResponse])
async def get_weather_forecast(
latitude: float = Query(..., description="Latitude"),
longitude: float = Query(..., description="Longitude"),
days: int = Query(7, description="Number of forecast days", ge=1, le=14),
request: WeatherForecastRequest,
tenant_id: UUID = Path(..., description="Tenant ID"),
current_user: Dict[str, Any] = Depends(get_current_user_dep),
):
"""Get weather forecast for location"""
try:
logger.debug("Getting weather forecast",
lat=latitude,
lon=longitude,
days=days,
lat=request.latitude,
lon=request.longitude,
days=request.days,
tenant_id=tenant_id)
forecast = await weather_service.get_weather_forecast(latitude, longitude, days)
forecast = await weather_service.get_weather_forecast(request.latitude, request.longitude, request.days)
if not forecast:
raise HTTPException(status_code=404, detail="Weather forecast not available")
@@ -98,9 +97,9 @@ async def get_weather_forecast(
await publish_weather_updated({
"type": "forecast_requested",
"tenant_id": tenant_id,
"latitude": latitude,
"longitude": longitude,
"days": days,
"latitude": request.latitude,
"longitude": request.longitude,
"days": request.days,
"requested_by": current_user["user_id"],
"timestamp": datetime.utcnow().isoformat()
})