Improve the dahboard 4
This commit is contained in:
55
services/external/app/api/weather.py
vendored
55
services/external/app/api/weather.py
vendored
@@ -13,7 +13,9 @@ from app.schemas.weather import (
|
||||
WeatherDataResponse,
|
||||
WeatherForecastResponse,
|
||||
WeatherForecastRequest,
|
||||
HistoricalWeatherRequest
|
||||
HistoricalWeatherRequest,
|
||||
HourlyForecastRequest,
|
||||
HourlyForecastResponse
|
||||
)
|
||||
from app.services.weather_service import WeatherService
|
||||
from app.services.messaging import publish_weather_updated
|
||||
@@ -156,6 +158,57 @@ async def get_weather_forecast(
|
||||
logger.error("Failed to get weather forecast", error=str(e))
|
||||
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
||||
|
||||
@router.post("/tenants/{tenant_id}/weather/hourly-forecast", response_model=List[HourlyForecastResponse])
|
||||
async def get_hourly_weather_forecast(
|
||||
request: HourlyForecastRequest,
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
current_user: Dict[str, Any] = Depends(get_current_user_dep),
|
||||
):
|
||||
"""Get hourly weather forecast for location using AEMET API
|
||||
|
||||
This endpoint provides hourly weather predictions for up to 48 hours,
|
||||
perfect for detailed bakery operations planning and weather-based recommendations.
|
||||
"""
|
||||
try:
|
||||
logger.debug("Getting hourly weather forecast",
|
||||
lat=request.latitude,
|
||||
lon=request.longitude,
|
||||
hours=request.hours,
|
||||
tenant_id=tenant_id)
|
||||
|
||||
hourly_forecast = await weather_service.get_hourly_forecast(
|
||||
request.latitude, request.longitude, request.hours
|
||||
)
|
||||
|
||||
if not hourly_forecast:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Hourly weather forecast not available. Please check AEMET API configuration."
|
||||
)
|
||||
|
||||
# Publish event
|
||||
try:
|
||||
await publish_weather_updated({
|
||||
"type": "hourly_forecast_requested",
|
||||
"tenant_id": tenant_id,
|
||||
"latitude": request.latitude,
|
||||
"longitude": request.longitude,
|
||||
"hours": request.hours,
|
||||
"requested_by": current_user["user_id"],
|
||||
"forecast_count": len(hourly_forecast),
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
})
|
||||
except Exception as e:
|
||||
logger.warning("Failed to publish hourly forecast event", error=str(e))
|
||||
|
||||
return hourly_forecast
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error("Failed to get hourly weather forecast", error=str(e))
|
||||
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
||||
|
||||
@router.get("/weather/status")
|
||||
async def get_weather_status():
|
||||
"""Get AEMET API status and diagnostics"""
|
||||
|
||||
Reference in New Issue
Block a user