From 23d428105850ba40c5ee584ed3c06deaac7bb749 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 29 Apr 2026 06:33:23 +0200 Subject: [PATCH] feat: refine exercise focus area retrieval in training planning - Updated the SQL query in the training planning module to fetch the primary exercise focus area more efficiently. - Enhanced error handling in the API utility to provide clearer feedback on potential issues, including CORS and URL errors, improving debugging for developers. --- backend/routers/training_planning.py | 8 +++++++- frontend/src/utils/api.js | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/routers/training_planning.py b/backend/routers/training_planning.py index 48403a8..cc9a34c 100644 --- a/backend/routers/training_planning.py +++ b/backend/routers/training_planning.py @@ -117,7 +117,13 @@ def _fetch_sections(cur, unit_id: int) -> List[Dict[str, Any]]: SELECT tusi.*, e.title AS exercise_title, e.summary AS exercise_summary, - e.focus_area AS exercise_focus_area, + ( + SELECT fa.name FROM exercise_focus_areas efa + JOIN focus_areas fa ON fa.id = efa.focus_area_id + WHERE efa.exercise_id = e.id + ORDER BY efa.is_primary DESC NULLS LAST, fa.name ASC + LIMIT 1 + ) AS exercise_focus_area, ev.variant_name AS exercise_variant_name FROM training_unit_section_items tusi LEFT JOIN exercises e ON tusi.exercise_id = e.id diff --git a/frontend/src/utils/api.js b/frontend/src/utils/api.js index 02496ca..3371692 100644 --- a/frontend/src/utils/api.js +++ b/frontend/src/utils/api.js @@ -43,7 +43,9 @@ async function request(endpoint, options = {}) { API_URL && API_URL.length > 0 ? `Verbindung zum API unter ${API_URL} fehlgeschlagen. Läuft das Backend (z. B. Port 8098) und ist CORS erlaubt?` : 'Kein VITE_API_URL gesetzt: Anfragen gehen an die Frontend-URL und schlagen oft fehl. Setze in .env z. B. VITE_API_URL=http://localhost:8098 und starte Vite neu.' - throw new Error(hint) + // Ursache oft: CORS (v. a. bei Fehler-Antworten ohne CORS-Header), Adblocker, falsche URL — + // Login kann trotzdem klappen wenn nur eine andere Route betroffen ist. + throw new Error(`${hint} [Technisch: ${e.message}; URL war ${endpoint}]`) } throw e }