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

@@ -18,8 +18,10 @@ from ..services.dashboard_service import DashboardService
from shared.clients import (
get_inventory_client,
get_production_client,
get_alerts_client,
ProductionServiceClient,
InventoryServiceClient
InventoryServiceClient,
AlertsServiceClient
)
from shared.clients.procurement_client import ProcurementServiceClient
@@ -29,6 +31,7 @@ logger = logging.getLogger(__name__)
inventory_client = get_inventory_client(settings, "orchestrator")
production_client = get_production_client(settings, "orchestrator")
procurement_client = ProcurementServiceClient(settings)
alerts_client = get_alerts_client(settings, "orchestrator")
router = APIRouter(prefix="/api/v1/tenants/{tenant_id}/dashboard", tags=["dashboard"])
@@ -191,7 +194,7 @@ async def get_bakery_health_status(
# Get alerts summary
try:
alerts_data = await procurement_client.get_alerts_summary(tenant_id) or {}
alerts_data = await alerts_client.get_alerts_summary(tenant_id) or {}
critical_alerts = alerts_data.get("critical_count", 0)
except Exception as e:
logger.warning(f"Failed to fetch alerts: {e}")
@@ -331,7 +334,7 @@ async def get_action_queue(
# Get critical alerts
critical_alerts = []
try:
alerts_data = await procurement_client.get_critical_alerts(tenant_id, limit=20)
alerts_data = await alerts_client.get_critical_alerts(tenant_id, limit=20)
if alerts_data:
critical_alerts = alerts_data.get("alerts", [])
except Exception as e: