feat: update version to 0.7.8 and enhance exercise variant handling
- Incremented application version to 0.7.8 and updated database schema version to 20260427030. - Added support for including exercise variants in the exercise listing API, improving training planning capabilities. - Enhanced training unit creation and update logic to validate exercise variant IDs, ensuring proper associations. - Updated frontend components to support exercise variant selection, improving user experience in training planning.
This commit is contained in:
1 parent
2c831d6cea
commit
cf9f95377c
6 files changed
+190
-39
No files matched your search
@@ -489,11 +489,16 @@ def list_exercises(
|
||||
),
|
||||
limit: int = Query(default=50, ge=1, le=100),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
include_variants: bool = Query(
|
||||
default=False,
|
||||
description="Wenn true: Feld variants[] pro Übung (id, variant_name, sequence_order) für Planung/UI",
|
||||
),
|
||||
session: dict = Depends(require_auth),
|
||||
):
|
||||
"""
|
||||
Liste aller Übungen mit Filtern.
|
||||
Lightweight Response (ohne M:N Details, nur IDs und Namen).
|
||||
Optional include_variants für Variantenauswahl in der Trainingsplanung.
|
||||
"""
|
||||
profile_id = session["profile_id"]
|
||||
|
||||
@@ -589,6 +594,25 @@ def list_exercises(
|
||||
where.append("e.search_vector @@ plainto_tsquery('german', %s)")
|
||||
params.append(qtext)
|
||||
|
||||
variants_sql = ""
|
||||
if include_variants:
|
||||
variants_sql = """,
|
||||
(
|
||||
SELECT COALESCE(
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', ev.id,
|
||||
'variant_name', ev.variant_name,
|
||||
'sequence_order', ev.sequence_order
|
||||
)
|
||||
ORDER BY ev.sequence_order NULLS LAST, ev.id
|
||||
),
|
||||
'[]'::json
|
||||
)
|
||||
FROM exercise_variants ev
|
||||
WHERE ev.exercise_id = e.id
|
||||
) AS variants"""
|
||||
|
||||
# Query (primary_focus_name für Listen-Ansicht gemäß Spec-Beispiel „focus_area“-Label)
|
||||
query = f"""
|
||||
SELECT e.id, e.title, e.summary, e.visibility, e.status,
|
||||
@@ -602,6 +626,7 @@ def list_exercises(
|
||||
ORDER BY efa.is_primary DESC NULLS LAST, fa.name ASC
|
||||
LIMIT 1
|
||||
) AS primary_focus_name
|
||||
{variants_sql}
|
||||
FROM exercises e
|
||||
LEFT JOIN profiles p ON e.created_by = p.id
|
||||
LEFT JOIN clubs c ON e.club_id = c.id
|
||||
@@ -619,6 +644,15 @@ def list_exercises(
|
||||
d = r2d(r)
|
||||
pfn = d.get("primary_focus_name")
|
||||
d["focus_area"] = pfn
|
||||
if include_variants:
|
||||
v = d.get("variants")
|
||||
if isinstance(v, str):
|
||||
try:
|
||||
d["variants"] = json.loads(v)
|
||||
except Exception:
|
||||
d["variants"] = []
|
||||
elif v is None:
|
||||
d["variants"] = []
|
||||
out.append(d)
|
||||
return out
|
||||
|
||||
|
||||
Reference in new issue
Block a user