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.
This commit is contained in:
@@ -192,7 +192,7 @@ async def get_bakery_health_status(
|
|||||||
# Get alerts - using base client for alert service
|
# Get alerts - using base client for alert service
|
||||||
try:
|
try:
|
||||||
alerts_data = await procurement_client.get(
|
alerts_data = await procurement_client.get(
|
||||||
"/alert-processor/alerts/summary",
|
"/procurement/alert-processor/alerts/summary",
|
||||||
tenant_id=tenant_id
|
tenant_id=tenant_id
|
||||||
) or {}
|
) or {}
|
||||||
critical_alerts = alerts_data.get("critical_count", 0)
|
critical_alerts = alerts_data.get("critical_count", 0)
|
||||||
@@ -203,7 +203,7 @@ async def get_bakery_health_status(
|
|||||||
# Get pending PO count
|
# Get pending PO count
|
||||||
try:
|
try:
|
||||||
po_data = await procurement_client.get(
|
po_data = await procurement_client.get(
|
||||||
f"/purchase-orders",
|
"/procurement/purchase-orders",
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
params={"status": "pending_approval", "limit": 100}
|
params={"status": "pending_approval", "limit": 100}
|
||||||
) or {}
|
) or {}
|
||||||
@@ -215,7 +215,7 @@ async def get_bakery_health_status(
|
|||||||
# Get production delays
|
# Get production delays
|
||||||
try:
|
try:
|
||||||
prod_data = await production_client.get(
|
prod_data = await production_client.get(
|
||||||
"/production-batches",
|
"/production/production-batches",
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
params={"status": "ON_HOLD", "limit": 100}
|
params={"status": "ON_HOLD", "limit": 100}
|
||||||
) or {}
|
) or {}
|
||||||
@@ -277,7 +277,7 @@ async def get_orchestration_summary(
|
|||||||
if summary["purchaseOrdersCreated"] > 0:
|
if summary["purchaseOrdersCreated"] > 0:
|
||||||
try:
|
try:
|
||||||
po_data = await procurement_client.get(
|
po_data = await procurement_client.get(
|
||||||
"/purchase-orders",
|
"/procurement/purchase-orders",
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
params={"status": "pending_approval", "limit": 10}
|
params={"status": "pending_approval", "limit": 10}
|
||||||
)
|
)
|
||||||
@@ -297,7 +297,7 @@ async def get_orchestration_summary(
|
|||||||
if summary["productionBatchesCreated"] > 0:
|
if summary["productionBatchesCreated"] > 0:
|
||||||
try:
|
try:
|
||||||
batch_data = await production_client.get(
|
batch_data = await production_client.get(
|
||||||
"/production-batches/today",
|
"/production/production-batches/today",
|
||||||
tenant_id=tenant_id
|
tenant_id=tenant_id
|
||||||
)
|
)
|
||||||
if batch_data:
|
if batch_data:
|
||||||
@@ -339,7 +339,7 @@ async def get_action_queue(
|
|||||||
pending_pos = []
|
pending_pos = []
|
||||||
try:
|
try:
|
||||||
po_data = await procurement_client.get(
|
po_data = await procurement_client.get(
|
||||||
"/purchase-orders",
|
"/procurement/purchase-orders",
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
params={"status": "pending_approval", "limit": 20}
|
params={"status": "pending_approval", "limit": 20}
|
||||||
)
|
)
|
||||||
@@ -352,7 +352,7 @@ async def get_action_queue(
|
|||||||
critical_alerts = []
|
critical_alerts = []
|
||||||
try:
|
try:
|
||||||
alerts_data = await procurement_client.get(
|
alerts_data = await procurement_client.get(
|
||||||
"/alert-processor/alerts",
|
"/procurement/alert-processor/alerts",
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
params={"severity": "critical", "resolved": False, "limit": 20}
|
params={"severity": "critical", "resolved": False, "limit": 20}
|
||||||
)
|
)
|
||||||
@@ -366,7 +366,7 @@ async def get_action_queue(
|
|||||||
onboarding_steps = []
|
onboarding_steps = []
|
||||||
try:
|
try:
|
||||||
onboarding_data = await procurement_client.get(
|
onboarding_data = await procurement_client.get(
|
||||||
"/auth/onboarding-progress",
|
"/procurement/auth/onboarding-progress",
|
||||||
tenant_id=tenant_id
|
tenant_id=tenant_id
|
||||||
)
|
)
|
||||||
if onboarding_data:
|
if onboarding_data:
|
||||||
@@ -417,7 +417,7 @@ async def get_production_timeline(
|
|||||||
batches = []
|
batches = []
|
||||||
try:
|
try:
|
||||||
batch_data = await production_client.get(
|
batch_data = await production_client.get(
|
||||||
"/production-batches/today",
|
"/production/production-batches/today",
|
||||||
tenant_id=tenant_id
|
tenant_id=tenant_id
|
||||||
)
|
)
|
||||||
if batch_data:
|
if batch_data:
|
||||||
@@ -467,7 +467,7 @@ async def get_insights(
|
|||||||
sustainability_data = {}
|
sustainability_data = {}
|
||||||
try:
|
try:
|
||||||
sustainability_data = await inventory_client.get(
|
sustainability_data = await inventory_client.get(
|
||||||
"/sustainability/widget",
|
"/inventory/sustainability/widget",
|
||||||
tenant_id=tenant_id
|
tenant_id=tenant_id
|
||||||
) or {}
|
) or {}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -476,10 +476,22 @@ async def get_insights(
|
|||||||
# Inventory data
|
# Inventory data
|
||||||
inventory_data = {}
|
inventory_data = {}
|
||||||
try:
|
try:
|
||||||
inventory_data = await inventory_client.get(
|
raw_inventory_data = await inventory_client.get(
|
||||||
"/inventory/dashboard/stock-status",
|
"/inventory/dashboard/stock-status",
|
||||||
tenant_id=tenant_id
|
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:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to fetch inventory data: {e}")
|
logger.warning(f"Failed to fetch inventory data: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user