summaryrefslogtreecommitdiff
path: root/internal/handlers/main.go
diff options
context:
space:
mode:
authorGrail Finder (aider) <wohilas@gmail.com>2025-04-06 09:53:03 +0300
committerGrail Finder (aider) <wohilas@gmail.com>2025-04-06 09:53:03 +0300
commit95c3ebfaf9fdb1e65e3dfaef177e4b6d20344009 (patch)
tree43acb05942de0cf8bb8508a3c2a225725b4da89d /internal/handlers/main.go
parentbbdb2f7864b9c218e9cdfca62435a32b0a482b9f (diff)
feat: add mixed exercise endpoint handler
Diffstat (limited to 'internal/handlers/main.go')
-rw-r--r--internal/handlers/main.go25
1 files changed, 25 insertions, 0 deletions
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)