feat: add reference values snapshot endpoints and data layer functions
Deploy Development / deploy (push) Successful in 1m3s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

- Introduced `get_profile_reference_values_current_snapshot` and `get_profile_reference_values_recent_snapshot` functions to retrieve current and recent reference values for profiles.
- Updated the placeholder resolver to include new placeholders for current and recent reference values.
- Added new API endpoints for fetching current and recent reference values snapshots.
- Enhanced the frontend API utility to support the new snapshot endpoints.
- Improved unit tests to validate the new data layer functions and their behavior.
This commit is contained in:
Lars committed 2026-04-19 10:52:31 +02:00
1 parent df0165bee3
commit 42ae796448
7 files changed
+359 -1

No files matched your search

+44
View File
@@ -19,6 +19,8 @@ from psycopg2.extras import Json
from auth import require_auth
from data_layer.reference_values import (
fetch_reference_type_by_key,
get_profile_reference_values_current_snapshot,
get_profile_reference_values_recent_snapshot,
get_profile_reference_values_summary,
list_active_reference_value_types_data,
list_profile_reference_values_for_type,
@@ -93,6 +95,48 @@ def profile_reference_values_summary(
return get_profile_reference_values_summary(pid)
@router.get("/profile-reference-values/snapshot-current")
def profile_reference_values_snapshot_current(
x_profile_id: Optional[str] = Header(default=None),
session: dict = Depends(require_auth),
):
"""
Layer 1: Alle aktuellen Referenzwerte (jüngster Eintrag pro Typ), wie Platzhalter
``{{reference_values_current_json}}``.
"""
pid = get_pid(x_profile_id)
return get_profile_reference_values_current_snapshot(pid)
@router.get("/profile-reference-values/snapshot-recent")
def profile_reference_values_snapshot_recent(
limit_per_type: int = Query(5, ge=1, le=50, description="Einträge pro Referenztyp (neueste zuerst)"),
date_from: Optional[str] = Query(None, description="Filter effective_date >= (YYYY-MM-DD)"),
date_to: Optional[str] = Query(None, description="Filter effective_date <= (YYYY-MM-DD)"),
x_profile_id: Optional[str] = Header(default=None),
session: dict = Depends(require_auth),
):
"""
Layer 1: Bis zu N Einträge pro Typ (Verlauf), wie Platzhalter ``{{reference_values_recent_json}}``.
"""
pid = get_pid(x_profile_id)
df = date_from
dto = date_to
for label, raw in (("date_from", df), ("date_to", dto)):
if raw is None or not str(raw).strip():
continue
try:
datetime.strptime(str(raw).strip(), "%Y-%m-%d")
except ValueError:
raise HTTPException(400, f"{label}: Ungültiges Datum, Format YYYY-MM-DD")
return get_profile_reference_values_recent_snapshot(
pid,
limit_per_type=limit_per_type,
date_from=df,
date_to=dto,
)
@router.get("/profile-reference-values")
def list_profile_reference_values(
type_key: str = Query(..., description="Schlüssel aus reference_value_types.key"),