REFACTOR ALL APIs

This commit is contained in:
Urtzi Alfaro
2025-10-06 15:27:01 +02:00
parent dc8221bd2f
commit 38fb98bc27
166 changed files with 18454 additions and 13605 deletions

View File

@@ -13,6 +13,8 @@ from sqlalchemy.ext.asyncio import AsyncSession
import structlog
from shared.auth.decorators import get_current_user_dep
from shared.auth.access_control import require_user_role, analytics_tier_required
from shared.routing import RouteBuilder
from app.core.database import get_db
from app.services.inventory_service import InventoryService
from app.services.food_safety_service import FoodSafetyService
@@ -31,6 +33,9 @@ from app.schemas.dashboard import (
logger = structlog.get_logger()
# Create route builder for consistent URL structure
route_builder = RouteBuilder('inventory')
router = APIRouter(tags=["dashboard"])
@@ -46,7 +51,10 @@ async def get_dashboard_service(db: AsyncSession = Depends(get_db)) -> Dashboard
# ===== Main Dashboard Endpoints =====
@router.get("/tenants/{tenant_id}/dashboard/summary", response_model=InventoryDashboardSummary)
@router.get(
route_builder.build_dashboard_route("summary"),
response_model=InventoryDashboardSummary
)
async def get_inventory_dashboard_summary(
tenant_id: UUID = Path(...),
filters: Optional[DashboardFilter] = None,
@@ -74,7 +82,10 @@ async def get_inventory_dashboard_summary(
)
@router.get("/tenants/{tenant_id}/dashboard/food-safety", response_model=FoodSafetyDashboard)
@router.get(
route_builder.build_dashboard_route("food-safety"),
response_model=FoodSafetyDashboard
)
async def get_food_safety_dashboard(
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
@@ -101,7 +112,11 @@ async def get_food_safety_dashboard(
)
@router.get("/tenants/{tenant_id}/dashboard/analytics", response_model=InventoryAnalytics)
@router.get(
route_builder.build_dashboard_route("analytics"),
response_model=InventoryAnalytics
)
@analytics_tier_required
async def get_inventory_analytics(
tenant_id: UUID = Path(...),
days_back: int = Query(30, ge=1, le=365, description="Number of days to analyze"),
@@ -129,7 +144,10 @@ async def get_inventory_analytics(
)
@router.get("/tenants/{tenant_id}/dashboard/business-model", response_model=BusinessModelInsights)
@router.get(
route_builder.build_dashboard_route("business-model"),
response_model=BusinessModelInsights
)
async def get_business_model_insights(
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
@@ -158,7 +176,10 @@ async def get_business_model_insights(
# ===== Detailed Dashboard Data Endpoints =====
@router.get("/tenants/{tenant_id}/dashboard/stock-status", response_model=List[StockStatusSummary])
@router.get(
route_builder.build_dashboard_route("stock-status"),
response_model=List[StockStatusSummary]
)
async def get_stock_status_by_category(
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
@@ -181,7 +202,10 @@ async def get_stock_status_by_category(
)
@router.get("/tenants/{tenant_id}/dashboard/alerts-summary", response_model=List[AlertSummary])
@router.get(
route_builder.build_dashboard_route("alerts-summary"),
response_model=List[AlertSummary]
)
async def get_alerts_summary(
tenant_id: UUID = Path(...),
filters: Optional[AlertsFilter] = None,
@@ -205,7 +229,10 @@ async def get_alerts_summary(
)
@router.get("/tenants/{tenant_id}/dashboard/recent-activity", response_model=List[RecentActivity])
@router.get(
route_builder.build_dashboard_route("recent-activity"),
response_model=List[RecentActivity]
)
async def get_recent_activity(
tenant_id: UUID = Path(...),
limit: int = Query(20, ge=1, le=100, description="Number of activities to return"),
@@ -234,7 +261,9 @@ async def get_recent_activity(
# ===== Real-time Data Endpoints =====
@router.get("/tenants/{tenant_id}/dashboard/live-metrics")
@router.get(
route_builder.build_dashboard_route("live-metrics")
)
async def get_live_metrics(
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
@@ -261,7 +290,9 @@ async def get_live_metrics(
)
@router.get("/tenants/{tenant_id}/dashboard/temperature-status")
@router.get(
route_builder.build_dashboard_route("temperature-status")
)
async def get_temperature_monitoring_status(
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep),
@@ -289,7 +320,9 @@ async def get_temperature_monitoring_status(
# ===== Dashboard Configuration Endpoints =====
@router.get("/tenants/{tenant_id}/dashboard/config")
@router.get(
route_builder.build_dashboard_route("config")
)
async def get_dashboard_config(
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep)
@@ -335,7 +368,9 @@ async def get_dashboard_config(
# ===== Export and Reporting Endpoints =====
@router.get("/tenants/{tenant_id}/export/summary")
@router.get(
route_builder.build_operations_route("export/summary")
)
async def export_dashboard_summary(
tenant_id: UUID = Path(...),
format: str = Query("json", description="Export format: json, csv, excel"),
@@ -380,7 +415,9 @@ async def export_dashboard_summary(
# ===== Health and Status Endpoints =====
@router.get("/tenants/{tenant_id}/health")
@router.get(
route_builder.build_base_route("health")
)
async def get_dashboard_health(
tenant_id: UUID = Path(...),
current_user: dict = Depends(get_current_user_dep)