REFACTOR API gateway
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
# services/data/app/api/weather.py - UPDATED WITH UNIFIED AUTH
|
||||
"""Weather data API endpoints with unified authentication"""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, BackgroundTasks
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, BackgroundTasks, Path
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime, date
|
||||
import structlog
|
||||
from uuid import UUID
|
||||
|
||||
from app.schemas.external import (
|
||||
WeatherDataResponse,
|
||||
@@ -19,14 +20,14 @@ from shared.auth.decorators import (
|
||||
get_current_tenant_id_dep
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/weather", tags=["weather"])
|
||||
router = APIRouter(tags=["weather"])
|
||||
logger = structlog.get_logger()
|
||||
|
||||
@router.get("/current", response_model=WeatherDataResponse)
|
||||
@router.get("/tenants/{tenant_id}/current", response_model=WeatherDataResponse)
|
||||
async def get_current_weather(
|
||||
latitude: float = Query(..., description="Latitude"),
|
||||
longitude: float = Query(..., description="Longitude"),
|
||||
tenant_id: str = Depends(get_current_tenant_id_dep),
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
current_user: Dict[str, Any] = Depends(get_current_user_dep),
|
||||
):
|
||||
"""Get current weather data for location"""
|
||||
@@ -64,12 +65,12 @@ async def get_current_weather(
|
||||
logger.error("Failed to get current weather", error=str(e))
|
||||
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
||||
|
||||
@router.get("/forecast", response_model=List[WeatherForecastResponse])
|
||||
@router.get("/tenants/{tenant_id}/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),
|
||||
tenant_id: str = Depends(get_current_tenant_id_dep),
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
current_user: Dict[str, Any] = Depends(get_current_user_dep),
|
||||
):
|
||||
"""Get weather forecast for location"""
|
||||
@@ -108,13 +109,13 @@ 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.get("/history", response_model=List[WeatherDataResponse])
|
||||
@router.get("/tenants/{tenant_id}/history", response_model=List[WeatherDataResponse])
|
||||
async def get_weather_history(
|
||||
start_date: date = Query(..., description="Start date"),
|
||||
end_date: date = Query(..., description="End date"),
|
||||
latitude: float = Query(..., description="Latitude"),
|
||||
longitude: float = Query(..., description="Longitude"),
|
||||
tenant_id: str = Depends(get_current_tenant_id_dep)
|
||||
tenant_id: str = Path(..., description="Tenant ID")
|
||||
):
|
||||
"""Get historical weather data"""
|
||||
try:
|
||||
@@ -134,11 +135,11 @@ async def get_weather_history(
|
||||
logger.error("Failed to get weather history", error=str(e))
|
||||
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
||||
|
||||
@router.post("/sync")
|
||||
@router.post("/tenants/{tenant_id}/sync")
|
||||
async def sync_weather_data(
|
||||
background_tasks: BackgroundTasks,
|
||||
force: bool = Query(False, description="Force sync even if recently synced"),
|
||||
tenant_id: str = Depends(get_current_tenant_id_dep),
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
current_user: Dict[str, Any] = Depends(get_current_user_dep),
|
||||
):
|
||||
"""Manually trigger weather data synchronization"""
|
||||
|
||||
Reference in New Issue
Block a user