refactor: Extract alerts functionality to dedicated AlertsServiceClient

Moved alert-related methods from ProcurementServiceClient to a new
dedicated AlertsServiceClient for better separation of concerns.

Changes:
- Created shared/clients/alerts_client.py:
  * get_alerts_summary() - Alert counts by severity/status
  * get_critical_alerts() - Filtered list of urgent alerts
  * get_alerts_by_severity() - Filter by any severity level
  * get_alert_by_id() - Get specific alert details
  * Includes severity mapping (critical → urgent)

- Updated shared/clients/__init__.py:
  * Added AlertsServiceClient import/export
  * Added get_alerts_client() factory function

- Updated procurement_client.py:
  * Removed get_critical_alerts() method
  * Removed get_alerts_summary() method
  * Kept only procurement-specific methods

- Updated dashboard.py:
  * Import and initialize alerts_client
  * Use alerts_client for alert operations
  * Use procurement_client only for procurement operations

Benefits:
- Better separation of concerns
- Alerts logically grouped with alert_processor service
- Cleaner, more maintainable service client architecture
- Each client maps to its domain service
This commit is contained in:
Claude
2025-11-07 22:19:24 +00:00
parent eecd630d64
commit bc97fc0d1a
4 changed files with 193 additions and 56 deletions

View File

@@ -602,55 +602,3 @@ class ProcurementServiceClient(BaseServiceClient):
except Exception as e:
logger.error("Error fetching pending purchase orders", error=str(e), tenant_id=tenant_id)
return None
async def get_critical_alerts(
self,
tenant_id: str,
limit: int = 20
) -> Optional[Dict[str, Any]]:
"""
Get critical alerts for dashboard
Note: "critical" maps to "urgent" severity in alert_processor service
Args:
tenant_id: Tenant ID
limit: Maximum number of alerts to return
Returns:
Dict with {"alerts": [...], "total": n}
"""
try:
# Gateway routes /tenants/{tenant_id}/alerts/... to alert_processor service
# "critical" in dashboard = "urgent" severity in alert_processor
return await self.get(
"/alerts",
tenant_id=tenant_id,
params={"severity": "urgent", "resolved": False, "limit": limit}
)
except Exception as e:
logger.error("Error fetching critical alerts", error=str(e), tenant_id=tenant_id)
return None
async def get_alerts_summary(
self,
tenant_id: str
) -> Optional[Dict[str, Any]]:
"""
Get alerts summary for dashboard health status
Args:
tenant_id: Tenant ID
Returns:
Dict with counts by severity (critical_count maps to urgent severity)
"""
try:
# Gateway routes /tenants/{tenant_id}/alerts/... to alert_processor service
return await self.get(
"/alerts/summary",
tenant_id=tenant_id
)
except Exception as e:
logger.error("Error fetching alerts summary", error=str(e), tenant_id=tenant_id)
return None