Improve the frontend
This commit is contained in:
@@ -36,7 +36,8 @@ app = FastAPI(
|
||||
description="Central API Gateway for bakery forecasting microservices",
|
||||
version="1.0.0",
|
||||
docs_url="/docs",
|
||||
redoc_url="/redoc"
|
||||
redoc_url="/redoc",
|
||||
redirect_slashes=False # Disable automatic trailing slash redirects
|
||||
)
|
||||
|
||||
# Initialize metrics collector
|
||||
|
||||
@@ -178,13 +178,23 @@ async def proxy_tenant_notifications(request: Request, tenant_id: str = Path(...
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/notifications/{path}".rstrip("/")
|
||||
return await _proxy_to_notification_service(request, target_path)
|
||||
|
||||
# ================================================================
|
||||
# TENANT-SCOPED ALERT ANALYTICS ENDPOINTS (Must come BEFORE inventory alerts)
|
||||
# ================================================================
|
||||
|
||||
@router.api_route("/{tenant_id}/alerts/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_alert_analytics(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant alert analytics requests to alert processor service"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/alerts/{path}".rstrip("/")
|
||||
return await _proxy_to_alert_processor_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
# ================================================================
|
||||
# TENANT-SCOPED INVENTORY SERVICE ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
@router.api_route("/{tenant_id}/alerts{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_alerts(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant alerts requests to inventory service"""
|
||||
async def proxy_tenant_alerts_inventory(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant alerts requests to inventory service (legacy/food-safety alerts)"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/alerts{path}".rstrip("/")
|
||||
return await _proxy_to_inventory_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
@@ -252,9 +262,15 @@ async def proxy_tenant_production(request: Request, tenant_id: str = Path(...),
|
||||
# TENANT-SCOPED ORDERS SERVICE ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
@router.api_route("/{tenant_id}/orders", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_orders_base(request: Request, tenant_id: str = Path(...)):
|
||||
"""Proxy tenant orders requests to orders service (base path)"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/orders"
|
||||
return await _proxy_to_orders_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
@router.api_route("/{tenant_id}/orders/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_orders(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant orders requests to orders service"""
|
||||
async def proxy_tenant_orders_with_path(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant orders requests to orders service (with additional path)"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/orders/{path}".rstrip("/")
|
||||
return await _proxy_to_orders_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
@@ -287,7 +303,7 @@ async def proxy_tenant_suppliers(request: Request, tenant_id: str = Path(...), p
|
||||
@router.api_route("/{tenant_id}/purchase-orders{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_purchase_orders(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant purchase order requests to suppliers service"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/purchase-orders{path}".rstrip("/")
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/suppliers/purchase-orders{path}".rstrip("/")
|
||||
return await _proxy_to_suppliers_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
@router.api_route("/{tenant_id}/deliveries{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
@@ -374,6 +390,10 @@ async def _proxy_to_pos_service(request: Request, target_path: str, tenant_id: s
|
||||
"""Proxy request to POS service"""
|
||||
return await _proxy_request(request, target_path, settings.POS_SERVICE_URL, tenant_id=tenant_id)
|
||||
|
||||
async def _proxy_to_alert_processor_service(request: Request, target_path: str, tenant_id: str = None):
|
||||
"""Proxy request to alert processor service"""
|
||||
return await _proxy_request(request, target_path, settings.ALERT_PROCESSOR_SERVICE_URL, tenant_id=tenant_id)
|
||||
|
||||
async def _proxy_request(request: Request, target_path: str, service_url: str, tenant_id: str = None):
|
||||
"""Generic proxy function with enhanced error handling"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user