From 9722cdb7f71db92a49ef20384b8985ccbd85500a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Nov 2025 22:08:17 +0000 Subject: [PATCH] fix: Add service prefixes to client endpoint paths and handle list responses Fixed 404 errors by adding service name prefixes to all client endpoint calls. Gateway routing requires paths like /production/..., /procurement/..., /inventory/... Changes: - Production endpoints: Add /production/ prefix - Procurement endpoints: Add /procurement/ prefix - Inventory endpoints: Add /inventory/ prefix - Handle inventory API returning list instead of dict for stock-status Fixes: - 404 errors for production-batches, purchase-orders, alerts endpoints - AttributeError when inventory_data is a list All service client calls now match gateway routing expectations. --- services/orchestrator/app/api/dashboard.py | 36 ++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/services/orchestrator/app/api/dashboard.py b/services/orchestrator/app/api/dashboard.py index 7088612c..34bf0f4d 100644 --- a/services/orchestrator/app/api/dashboard.py +++ b/services/orchestrator/app/api/dashboard.py @@ -192,7 +192,7 @@ async def get_bakery_health_status( # Get alerts - using base client for alert service try: alerts_data = await procurement_client.get( - "/alert-processor/alerts/summary", + "/procurement/alert-processor/alerts/summary", tenant_id=tenant_id ) or {} critical_alerts = alerts_data.get("critical_count", 0) @@ -203,7 +203,7 @@ async def get_bakery_health_status( # Get pending PO count try: po_data = await procurement_client.get( - f"/purchase-orders", + "/procurement/purchase-orders", tenant_id=tenant_id, params={"status": "pending_approval", "limit": 100} ) or {} @@ -215,7 +215,7 @@ async def get_bakery_health_status( # Get production delays try: prod_data = await production_client.get( - "/production-batches", + "/production/production-batches", tenant_id=tenant_id, params={"status": "ON_HOLD", "limit": 100} ) or {} @@ -277,7 +277,7 @@ async def get_orchestration_summary( if summary["purchaseOrdersCreated"] > 0: try: po_data = await procurement_client.get( - "/purchase-orders", + "/procurement/purchase-orders", tenant_id=tenant_id, params={"status": "pending_approval", "limit": 10} ) @@ -297,7 +297,7 @@ async def get_orchestration_summary( if summary["productionBatchesCreated"] > 0: try: batch_data = await production_client.get( - "/production-batches/today", + "/production/production-batches/today", tenant_id=tenant_id ) if batch_data: @@ -339,7 +339,7 @@ async def get_action_queue( pending_pos = [] try: po_data = await procurement_client.get( - "/purchase-orders", + "/procurement/purchase-orders", tenant_id=tenant_id, params={"status": "pending_approval", "limit": 20} ) @@ -352,7 +352,7 @@ async def get_action_queue( critical_alerts = [] try: alerts_data = await procurement_client.get( - "/alert-processor/alerts", + "/procurement/alert-processor/alerts", tenant_id=tenant_id, params={"severity": "critical", "resolved": False, "limit": 20} ) @@ -366,7 +366,7 @@ async def get_action_queue( onboarding_steps = [] try: onboarding_data = await procurement_client.get( - "/auth/onboarding-progress", + "/procurement/auth/onboarding-progress", tenant_id=tenant_id ) if onboarding_data: @@ -417,7 +417,7 @@ async def get_production_timeline( batches = [] try: batch_data = await production_client.get( - "/production-batches/today", + "/production/production-batches/today", tenant_id=tenant_id ) if batch_data: @@ -467,7 +467,7 @@ async def get_insights( sustainability_data = {} try: sustainability_data = await inventory_client.get( - "/sustainability/widget", + "/inventory/sustainability/widget", tenant_id=tenant_id ) or {} except Exception as e: @@ -476,10 +476,22 @@ async def get_insights( # Inventory data inventory_data = {} try: - inventory_data = await inventory_client.get( + raw_inventory_data = await inventory_client.get( "/inventory/dashboard/stock-status", tenant_id=tenant_id - ) or {} + ) + # Handle case where API returns a list instead of dict + if isinstance(raw_inventory_data, dict): + inventory_data = raw_inventory_data + elif isinstance(raw_inventory_data, list): + # If it's a list, aggregate the data + inventory_data = { + "low_stock_count": sum(1 for item in raw_inventory_data if item.get("status") == "low_stock"), + "out_of_stock_count": sum(1 for item in raw_inventory_data if item.get("status") == "out_of_stock"), + "total_items": len(raw_inventory_data) + } + else: + inventory_data = {} except Exception as e: logger.warning(f"Failed to fetch inventory data: {e}")