All checks were successful
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / playwright-tests (push) Successful in 1m32s
- Implemented a new API endpoint for retrieving dashboard KPIs, providing a consolidated overview of drafts, personal exercises, and year-to-date completed units. - Updated the Dashboard component to utilize the new endpoint, enhancing data retrieval efficiency and user experience. - Added a helper function in the exercises router for programmatic access to exercise listings. - Updated versioning and changelog to reflect the addition of the dashboard feature.
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""
|
|
Dashboard: zusammengefasste Kennzahlen (ein Roundtrip statt mehrerer Listen).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from tenant_context import TenantContext, get_tenant_context
|
|
from routers.exercises import list_exercises_like_get
|
|
from routers.training_planning import list_training_units
|
|
|
|
router = APIRouter(prefix="/api", tags=["dashboard"])
|
|
|
|
|
|
@router.get("/dashboard/kpis")
|
|
def get_dashboard_kpis(tenant: TenantContext = Depends(get_tenant_context)):
|
|
"""
|
|
Kurzüberblick-KPIs wie bisher drei parallele Client-Aufrufe:
|
|
listExercises (Entwürfe), listExercises (meine), listTrainingUnits (completed im Kalenderjahr).
|
|
"""
|
|
year = date.today().year
|
|
year_start = f"{year}-01-01"
|
|
year_end = f"{year}-12-31"
|
|
|
|
draft_list = list_exercises_like_get(
|
|
tenant, created_by_me=True, status="draft", limit=100
|
|
)
|
|
mine_list = list_exercises_like_get(
|
|
tenant, created_by_me=True, status=None, limit=100
|
|
)
|
|
ytd_completed = list_training_units(
|
|
group_id=None,
|
|
club_id=None,
|
|
start_date=year_start,
|
|
end_date=year_end,
|
|
status="completed",
|
|
assigned_to_me=True,
|
|
debrief_pending=False,
|
|
sort="desc",
|
|
limit=250,
|
|
tenant=tenant,
|
|
)
|
|
|
|
draft_preview = [
|
|
{"id": int(ex["id"]), "title": ex.get("title") or f"Übung #{ex['id']}"}
|
|
for ex in draft_list[:8]
|
|
]
|
|
|
|
return {
|
|
"year": year,
|
|
"draft_count": len(draft_list),
|
|
"draft_capped": len(draft_list) >= 100,
|
|
"draft_preview": draft_preview,
|
|
"mine_count": len(mine_list),
|
|
"mine_capped": len(mine_list) >= 100,
|
|
"ytd_completed_count": len(ytd_completed),
|
|
"ytd_capped": len(ytd_completed) >= 250,
|
|
}
|