From 95c3ebfaf9fdb1e65e3dfaef177e4b6d20344009 Mon Sep 17 00:00:00 2001 From: "Grail Finder (aider)" Date: Sun, 6 Apr 2025 09:53:03 +0300 Subject: feat: add mixed exercise endpoint handler --- internal/handlers/main.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'internal/handlers/main.go') diff --git a/internal/handlers/main.go b/internal/handlers/main.go index c04fd4e..b6ce093 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -113,6 +113,31 @@ func getCorrectOption(q *models.Question) string { } } +func (h *Handlers) HandleMixedUbung(w http.ResponseWriter, r *http.Request) { + mixedID := r.URL.Query().Get("id") + if mixedID == "" { + h.log.Error("missing mixed ID parameter") + abortWithError(w, "Missing exercise ID") + return + } + + questions, err := h.repo.DBGetQuestionsByMixedID(mixedID) + if err != nil { + h.log.Error("failed to get questions for mixed exercise", "error", err, "mixed_id", mixedID) + abortWithError(w, "Failed to load exercise") + return + } + + if len(questions) == 0 { + h.log.Error("no questions found for mixed exercise", "mixed_id", mixedID) + abortWithError(w, "Exercise contains no questions") + return + } + + // Render first question in the sequence + h.renderQuestion(w, &questions[0]) +} + func (h *Handlers) HandleNextQuestion(w http.ResponseWriter, r *http.Request) { currentID := r.URL.Query().Get("current_id") currID, err := strconv.Atoi(currentID) -- cgit v1.2.3