feat: Add dedicated dashboard methods to service clients

Created typed, domain-specific methods in service clients instead of
using generic .get() calls with paths. This improves type safety,
discoverability, and maintainability.

Service Client Changes:
- ProcurementServiceClient:
  * get_pending_purchase_orders() - POs awaiting approval
  * get_critical_alerts() - Critical severity alerts
  * get_alerts_summary() - Alert counts by severity

- ProductionServiceClient:
  * get_todays_batches() - Today's production timeline
  * get_production_batches_by_status() - Filter by status

- InventoryServiceClient:
  * get_stock_status() - Dashboard stock metrics
  * get_sustainability_widget() - Sustainability data

Dashboard API Changes:
- Updated all endpoints to use new dedicated methods
- Cleaner, more maintainable code
- Better error handling and logging
- Fixed inventory data type handling (list vs dict)

Note: Alert endpoints return 404 - alert_processor service needs
endpoints: /alerts/summary and /alerts (filtered by severity).
This commit is contained in:
Claude
2025-11-07 22:12:21 +00:00
parent 9722cdb7f7
commit 6cd4ef0f56
4 changed files with 187 additions and 33 deletions

View File

@@ -651,6 +651,54 @@ class InventoryServiceClient(BaseServiceClient):
error=str(e), tenant_id=tenant_id)
return None
# ================================================================
# DASHBOARD METHODS
# ================================================================
async def get_stock_status(
self,
tenant_id: str
) -> Optional[Dict[str, Any]]:
"""
Get inventory stock status for dashboard insights
Args:
tenant_id: Tenant ID
Returns:
Dict with stock counts and status metrics
"""
try:
return await self.get(
"/inventory/dashboard/stock-status",
tenant_id=tenant_id
)
except Exception as e:
logger.error("Error fetching stock status", error=str(e), tenant_id=tenant_id)
return None
async def get_sustainability_widget(
self,
tenant_id: str
) -> Optional[Dict[str, Any]]:
"""
Get sustainability metrics for dashboard
Args:
tenant_id: Tenant ID
Returns:
Dict with sustainability metrics (waste, CO2, etc.)
"""
try:
return await self.get(
"/inventory/sustainability/widget",
tenant_id=tenant_id
)
except Exception as e:
logger.error("Error fetching sustainability widget", error=str(e), tenant_id=tenant_id)
return None
# ================================================================
# UTILITY METHODS
# ================================================================