Offer the current exercise through an explicit API switch.
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Failing after 29s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 16s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m42s

The exercise list turns the live catalog on or off for the caller's edit rights. A distribution key reads that current selection and the changes since its last cursor.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-23 15:37:25 +01:00
1 parent 4ad62b6e38
commit b59b7eae16
13 files changed
+488 -5

No files matched your search

+42 -1
View File
@@ -451,6 +451,11 @@ _MAX_BULK_METADATA_IDS = 500
_MAX_BULK_RELATION_IDS_PER_KIND = 80
class ExerciseApiOfferingPatch(BaseModel):
exercise_ids: list[int] = Field(..., min_length=1, max_length=_MAX_BULK_METADATA_IDS)
api_offered: bool
class ExerciseBulkMetadataPatch(BaseModel):
"""Massenänderung: Sichtbarkeit/Status und/oder Zuordnungen (Kataloge)."""
@@ -1501,6 +1506,41 @@ def _assert_can_delete_exercise(cur, tenant: TenantContext, row: dict) -> None:
)
@router.patch("/exercises/api-offering")
def patch_exercise_api_offering(
body: ExerciseApiOfferingPatch,
tenant: TenantContext = Depends(get_tenant_context),
):
"""Schaltet die aktuelle API-Bereitstellung. Rechte sind die Bearbeitungsrechte der Übung."""
unique_ids = sorted({int(item) for item in body.exercise_ids if item is not None and int(item) > 0})
if not unique_ids:
raise HTTPException(status_code=400, detail="Keine gültigen Übungs-IDs")
updated: List[Dict[str, Any]] = []
denied: List[Dict[str, Any]] = []
with get_db() as conn:
cur = get_cursor(conn)
for ex_id in unique_ids:
cur.execute("SELECT id, title FROM exercises WHERE id = %s", (ex_id,))
row = cur.fetchone()
if not row:
denied.append({"id": ex_id, "detail": "Übung nicht gefunden"})
continue
item = r2d(row)
try:
_assert_can_edit_exercise(cur, ex_id, tenant)
except HTTPException as exc:
detail = exc.detail if isinstance(exc.detail, str) else str(exc.detail)
denied.append({"id": ex_id, "title": item.get("title"), "detail": detail})
continue
cur.execute(
"UPDATE exercises SET api_offered = %s, updated_at = NOW() WHERE id = %s",
(bool(body.api_offered), ex_id),
)
updated.append({"id": ex_id, "title": item.get("title"), "api_offered": bool(body.api_offered)})
conn.commit()
return {"updated": updated, "denied": denied}
@router.patch("/exercises/bulk-metadata")
def bulk_patch_exercises_metadata(
body: ExerciseBulkMetadataPatch,
@@ -2140,7 +2180,7 @@ def list_exercises(
# 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,
SELECT e.id, e.title, e.summary, e.visibility, e.status, e.api_offered,
e.exercise_kind, e.method_archetype,
e.created_by, p.name as creator_name,
e.club_id, c.name as club_name,
@@ -2213,6 +2253,7 @@ def list_exercises(
d["training_type_names"] = _coerce_json_str_list(d.get("training_type_names"))
d["variant_count"] = int(d.get("variant_count") or 0)
d["media_count"] = int(d.get("media_count") or 0)
d["api_offered"] = bool(d.get("api_offered"))
if include_variants:
v = d.get("variants")
if isinstance(v, str):