41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""HTTP boundary for the operational Dashboard overview."""
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, Response
|
|
|
|
from app.dashboard.dependencies import get_dashboard_service
|
|
from app.dashboard.models import (
|
|
DashboardAccess,
|
|
DashboardOverviewResponse,
|
|
)
|
|
from app.dashboard.service import DashboardService
|
|
from app.identity import require_permission, user_has_permission
|
|
|
|
|
|
router = APIRouter(prefix="/api/dashboard", tags=["dashboard"])
|
|
DashboardUser = Annotated[dict, Depends(require_permission("dashboard.view"))]
|
|
DashboardServiceDependency = Annotated[
|
|
DashboardService,
|
|
Depends(get_dashboard_service),
|
|
]
|
|
|
|
|
|
@router.get("/overview", response_model=DashboardOverviewResponse)
|
|
def get_dashboard_overview(
|
|
current_user: DashboardUser,
|
|
service: DashboardServiceDependency,
|
|
response: Response,
|
|
) -> DashboardOverviewResponse:
|
|
response.headers["Cache-Control"] = "no-store"
|
|
return service.get_overview(
|
|
DashboardAccess(
|
|
can_view_miners=user_has_permission(current_user, "miners.view"),
|
|
can_view_repairs=user_has_permission(current_user, "repairs.view"),
|
|
can_view_locations=user_has_permission(
|
|
current_user,
|
|
"locations.view",
|
|
),
|
|
)
|
|
)
|