Start integrating the onboarding flow with backend 3
This commit is contained in:
@@ -179,6 +179,32 @@ async def proxy_tenant_orders(request: Request, tenant_id: str = Path(...), 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)
|
||||
|
||||
# ================================================================
|
||||
# TENANT-SCOPED SUPPLIER SERVICE ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
@router.api_route("/{tenant_id}/suppliers/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
@router.api_route("/{tenant_id}/suppliers", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_suppliers(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant supplier requests to suppliers service"""
|
||||
if path:
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/suppliers/{path}".rstrip("/")
|
||||
else:
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/suppliers"
|
||||
return await _proxy_to_suppliers_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
@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("/")
|
||||
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"])
|
||||
async def proxy_tenant_deliveries(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant delivery requests to suppliers service"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/deliveries{path}".rstrip("/")
|
||||
return await _proxy_to_suppliers_service(request, target_path, tenant_id=tenant_id)
|
||||
|
||||
# ================================================================
|
||||
# PROXY HELPER FUNCTIONS
|
||||
# ================================================================
|
||||
@@ -219,6 +245,10 @@ async def _proxy_to_orders_service(request: Request, target_path: str, tenant_id
|
||||
"""Proxy request to orders service"""
|
||||
return await _proxy_request(request, target_path, settings.ORDERS_SERVICE_URL, tenant_id=tenant_id)
|
||||
|
||||
async def _proxy_to_suppliers_service(request: Request, target_path: str, tenant_id: str = None):
|
||||
"""Proxy request to suppliers service"""
|
||||
return await _proxy_request(request, target_path, settings.SUPPLIERS_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"""
|
||||
|
||||
@@ -246,6 +276,15 @@ async def _proxy_request(request: Request, target_path: str, service_url: str, t
|
||||
if tenant_id:
|
||||
headers["X-Tenant-ID"] = tenant_id
|
||||
|
||||
# Add user context headers if available
|
||||
if hasattr(request.state, 'user') and request.state.user:
|
||||
user = request.state.user
|
||||
headers["x-user-id"] = str(user.get('user_id', ''))
|
||||
headers["x-user-email"] = str(user.get('email', ''))
|
||||
headers["x-user-role"] = str(user.get('role', 'user'))
|
||||
headers["x-user-full-name"] = str(user.get('full_name', ''))
|
||||
headers["x-tenant-id"] = tenant_id or str(user.get('tenant_id', ''))
|
||||
|
||||
# Get request body if present
|
||||
body = None
|
||||
if request.method in ["POST", "PUT", "PATCH"]:
|
||||
|
||||
Reference in New Issue
Block a user