fix: exercises.py - use direct VARCHAR for age_groups (no catalog table in Shinkan)
This commit is contained in:
parent
a6ea5b95eb
commit
a67cc5f812
|
|
@ -142,16 +142,15 @@ def enrich_exercise_detail(exercise_id: int, cur) -> dict:
|
|||
)
|
||||
exercise["target_groups"] = [r2d(r) for r in cur.fetchall()]
|
||||
|
||||
# Age Groups (M:N) - nur Namen, nicht Objekte
|
||||
# Age Groups (M:N) - direkt als VARCHAR gespeichert
|
||||
cur.execute(
|
||||
"""SELECT ag.name
|
||||
FROM exercise_age_groups eag
|
||||
JOIN age_groups ag ON eag.age_group_id = ag.id
|
||||
WHERE eag.exercise_id = %s
|
||||
ORDER BY ag.sort_order""",
|
||||
"""SELECT age_group
|
||||
FROM exercise_age_groups
|
||||
WHERE exercise_id = %s
|
||||
ORDER BY age_group""",
|
||||
(exercise_id,)
|
||||
)
|
||||
exercise["age_groups"] = [r["name"] for r in cur.fetchall()]
|
||||
exercise["age_groups"] = [r["age_group"] for r in cur.fetchall()]
|
||||
|
||||
# Skills (M:N) mit Levels und Intensity
|
||||
cur.execute(
|
||||
|
|
@ -226,19 +225,17 @@ def assign_exercise_relations(cur, conn, exercise_id: int, data: dict):
|
|||
(exercise_id, tg["target_group_id"], tg.get("is_primary", False))
|
||||
)
|
||||
|
||||
# Age Groups (Namen → IDs lookup)
|
||||
# Age Groups (direkt als VARCHAR, CHECK constraint validiert)
|
||||
if "age_groups" in data:
|
||||
cur.execute("DELETE FROM exercise_age_groups WHERE exercise_id = %s", (exercise_id,))
|
||||
for age_group_name in data["age_groups"]:
|
||||
cur.execute("SELECT id FROM age_groups WHERE name ILIKE %s", (age_group_name,))
|
||||
row = cur.fetchone()
|
||||
if row:
|
||||
try:
|
||||
cur.execute(
|
||||
"INSERT INTO exercise_age_groups (exercise_id, age_group_id) VALUES (%s, %s)",
|
||||
(exercise_id, row[0])
|
||||
"INSERT INTO exercise_age_groups (exercise_id, age_group) VALUES (%s, %s)",
|
||||
(exercise_id, age_group_name)
|
||||
)
|
||||
else:
|
||||
logger.warning("Age Group '%s' nicht im Katalog gefunden", age_group_name)
|
||||
except Exception as e:
|
||||
logger.warning("Age Group '%s' ungültig: %s", age_group_name, e)
|
||||
|
||||
# Skills
|
||||
if "skills" in data:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user