feat: Enhance activity session handling and schema retrieval
- Updated `get_activity_session_logical_unit` to support optional parameters for form training context, allowing for more flexible schema resolution. - Introduced a new endpoint `/attribute-schema` to fetch activity attribute schemas without an existing session, improving manual data entry capabilities. - Enhanced the `getActivitySession` API method to accept query parameters for training category and type, facilitating dynamic schema retrieval. - Updated the frontend `ActivityPage` to utilize the new schema fetching logic, ensuring a smoother user experience when managing activity sessions and metrics.
This commit is contained in:
1 parent
92e334dcd2
commit
1220ee54fb
4 files changed
+214
-21
No files matched your search
@@ -371,6 +371,25 @@ def get_activity_mappable_fields(session: dict = Depends(require_auth)):
|
||||
return get_mappable_activity_field_catalog(cur, pid)
|
||||
|
||||
|
||||
@router.get("/attribute-schema")
|
||||
def get_activity_attribute_schema(
|
||||
training_category: Optional[str] = Query(None),
|
||||
training_type_id: Optional[int] = Query(None),
|
||||
session: dict = Depends(require_auth),
|
||||
):
|
||||
"""
|
||||
Aufgelöstes Attributprofil (tcp/ttp) für Erfassung ohne bestehende Session —
|
||||
gleiche Logik wie resolve_activity_attribute_schema.
|
||||
"""
|
||||
from data_layer.activity_session_metrics import resolve_activity_attribute_schema
|
||||
|
||||
cat = (training_category or "").strip() or None
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
schema = resolve_activity_attribute_schema(cur, cat, training_type_id)
|
||||
return {"schema": schema}
|
||||
|
||||
|
||||
@router.put("/{eid}")
|
||||
def update_activity(eid: str, e: ActivityEntry, x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)):
|
||||
"""Update existing activity entry."""
|
||||
@@ -422,6 +441,12 @@ def replace_activity_metrics(
|
||||
@router.get("/{eid}")
|
||||
def get_activity_session(
|
||||
eid: str,
|
||||
use_form_schema: bool = Query(
|
||||
False,
|
||||
description="True: Schema aus Query training_category / training_type_id (Formular), nicht nur DB-Zeile",
|
||||
),
|
||||
training_category: Optional[str] = Query(None),
|
||||
training_type_id: Optional[int] = Query(None),
|
||||
session: dict = Depends(require_auth),
|
||||
):
|
||||
"""Session-Kopf + aufgelöstes Schema + EAV-Metriken (Layer 1)."""
|
||||
@@ -435,7 +460,14 @@ def get_activity_session(
|
||||
try:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
unit = get_activity_session_logical_unit(cur, pid, eid)
|
||||
unit = get_activity_session_logical_unit(
|
||||
cur,
|
||||
pid,
|
||||
eid,
|
||||
use_form_training_context=use_form_schema,
|
||||
form_training_category=training_category,
|
||||
form_training_type_id=training_type_id,
|
||||
)
|
||||
except ActivitySessionMetricsError as err:
|
||||
raise HTTPException(err.status_code, err.detail) from err
|
||||
unit["header"] = serialize_dates(unit["header"])
|
||||
|
||||
Reference in new issue
Block a user