Imporve gateway auth for all services

This commit is contained in:
Urtzi Alfaro
2025-07-21 14:41:33 +02:00
parent df7c6e1e00
commit 2d85dd3e9e
6 changed files with 188 additions and 63 deletions

View File

@@ -5,7 +5,7 @@
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.ext.asyncio import AsyncSession
from typing import List, Optional
from typing import List, Dict, Any
from datetime import datetime, timedelta
import structlog
@@ -19,6 +19,11 @@ from app.schemas.external import (
DateRangeRequest
)
from shared.auth.decorators import (
get_current_user_dep,
get_current_tenant_id_dep
)
router = APIRouter()
traffic_service = TrafficService()
logger = structlog.get_logger()
@@ -27,7 +32,7 @@ logger = structlog.get_logger()
async def get_current_traffic(
latitude: float = Query(..., description="Latitude"),
longitude: float = Query(..., description="Longitude"),
current_user: AuthInfo = Depends(get_current_user)
current_user: Dict[str, Any] = Depends(get_current_user_dep),
):
"""Get current traffic data for location"""
try:
@@ -72,7 +77,7 @@ async def get_historical_traffic(
start_date: datetime = Query(..., description="Start date"),
end_date: datetime = Query(..., description="End date"),
db: AsyncSession = Depends(get_db),
current_user: AuthInfo = Depends(get_current_user)
current_user: Dict[str, Any] = Depends(get_current_user_dep),
):
"""Get historical traffic data"""
try:
@@ -116,7 +121,7 @@ async def store_traffic_data(
latitude: float = Query(..., description="Latitude"),
longitude: float = Query(..., description="Longitude"),
db: AsyncSession = Depends(get_db),
current_user: AuthInfo = Depends(get_current_user)
current_user: Dict[str, Any] = Depends(get_current_user_dep)
):
"""Store current traffic data to database"""
try:

View File

@@ -6,10 +6,9 @@ from typing import List, Optional, Dict, Any
from datetime import datetime, date
import structlog
from app.schemas.weather import (
from app.schemas.external import (
WeatherDataResponse,
WeatherForecastResponse,
WeatherSummaryResponse
WeatherForecastResponse
)
from app.services.weather_service import WeatherService
from app.services.messaging import publish_weather_updated
@@ -136,35 +135,6 @@ 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.get("/summary", response_model=WeatherSummaryResponse)
async def get_weather_summary(
location_id: Optional[str] = Query(None, description="Location ID"),
days: int = Query(30, description="Number of days to summarize"),
tenant_id: str = Depends(get_current_tenant_id_dep),
current_user: Dict[str, Any] = Depends(get_current_user_dep),
):
"""Get weather summary for tenant's location"""
try:
logger.debug("Getting weather summary",
location_id=location_id,
days=days,
tenant_id=tenant_id)
weather_service = WeatherService()
# If no location_id provided, use tenant's default location
if not location_id:
# This would typically fetch from tenant service
location_id = tenant_id # Simplified for example
summary = await weather_service.get_weather_summary(location_id, days)
return summary
except Exception as e:
logger.error("Failed to get weather summary", error=str(e))
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
@router.post("/sync")
async def sync_weather_data(
background_tasks: BackgroundTasks,