feat: add operational Dashboard
This commit is contained in:
1 parent
4a1959ecd6
commit
b8b741ccee
23 files changed
+1278
-59
No files matched your search
@@ -0,0 +1,64 @@
|
||||
"""Composition service for permission-aware Dashboard summaries."""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from app.dashboard.models import (
|
||||
DashboardAccess,
|
||||
DashboardOverviewData,
|
||||
DashboardOverviewMeta,
|
||||
DashboardOverviewResponse,
|
||||
)
|
||||
from app.inventory.service import InventoryService
|
||||
from app.locations.service import LocationMapService
|
||||
from app.repairs.center_service import RepairCenterService
|
||||
|
||||
|
||||
class DashboardService:
|
||||
"""Coordinate domain-owned summaries without introducing new rules."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
inventory_service: InventoryService,
|
||||
repair_center_service: RepairCenterService,
|
||||
location_service: LocationMapService,
|
||||
):
|
||||
self.inventory_service = inventory_service
|
||||
self.repair_center_service = repair_center_service
|
||||
self.location_service = location_service
|
||||
|
||||
def get_overview(self, access: DashboardAccess) -> DashboardOverviewResponse:
|
||||
fleet = (
|
||||
self.inventory_service.summarize_fleet()
|
||||
if access.can_view_miners
|
||||
else None
|
||||
)
|
||||
repairs = (
|
||||
self.repair_center_service.summarize_active_repairs()
|
||||
if access.can_view_repairs
|
||||
else None
|
||||
)
|
||||
locations = (
|
||||
self.location_service.summarize_locations(
|
||||
include_miner_counts=access.can_view_miners
|
||||
)
|
||||
if access.can_view_locations
|
||||
else None
|
||||
)
|
||||
available_sections = [
|
||||
name
|
||||
for name, value in (
|
||||
("fleet", fleet),
|
||||
("repairs", repairs),
|
||||
("locations", locations),
|
||||
)
|
||||
if value is not None
|
||||
]
|
||||
return DashboardOverviewResponse(
|
||||
data=DashboardOverviewData(
|
||||
fleet=fleet,
|
||||
repairs=repairs,
|
||||
locations=locations,
|
||||
generated_at=datetime.now(timezone.utc),
|
||||
),
|
||||
meta=DashboardOverviewMeta(available_sections=available_sections),
|
||||
)
|
||||
Reference in new issue
Block a user