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:
@@ -17,6 +17,7 @@ from .recipes_client import RecipesServiceClient
|
||||
from .suppliers_client import SuppliersServiceClient
|
||||
from .tenant_client import TenantServiceClient
|
||||
from .ai_insights_client import AIInsightsClient
|
||||
from .alerts_client import AlertsServiceClient
|
||||
|
||||
# Import config
|
||||
from shared.config.base import BaseServiceSettings
|
||||
@@ -108,12 +109,22 @@ def get_suppliers_client(config: BaseServiceSettings = None, service_name: str =
|
||||
"""Get or create a suppliers service client"""
|
||||
if config is None:
|
||||
from app.core.config import settings as config
|
||||
|
||||
|
||||
cache_key = f"suppliers_{service_name}"
|
||||
if cache_key not in _client_cache:
|
||||
_client_cache[cache_key] = SuppliersServiceClient(config)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
def get_alerts_client(config: BaseServiceSettings = None, service_name: str = "unknown") -> AlertsServiceClient:
|
||||
"""Get or create an alerts service client"""
|
||||
if config is None:
|
||||
from app.core.config import settings as config
|
||||
|
||||
cache_key = f"alerts_{service_name}"
|
||||
if cache_key not in _client_cache:
|
||||
_client_cache[cache_key] = AlertsServiceClient(config, service_name)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
|
||||
class ServiceClients:
|
||||
"""Convenient wrapper for all service clients"""
|
||||
@@ -223,6 +234,7 @@ __all__ = [
|
||||
'ProductionServiceClient',
|
||||
'RecipesServiceClient',
|
||||
'SuppliersServiceClient',
|
||||
'AlertsServiceClient',
|
||||
'TenantServiceClient',
|
||||
'ServiceClients',
|
||||
'get_training_client',
|
||||
@@ -234,5 +246,6 @@ __all__ = [
|
||||
'get_production_client',
|
||||
'get_recipes_client',
|
||||
'get_suppliers_client',
|
||||
'get_alerts_client',
|
||||
'get_service_clients'
|
||||
]
|
||||
Reference in New Issue
Block a user