diff options
-rw-r--r-- | internal/handlers/main.go | 25 | ||||
-rw-r--r-- | internal/server/router.go | 1 |
2 files changed, 26 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) diff --git a/internal/server/router.go b/internal/server/router.go index 6553d55..bb73e71 100644 --- a/internal/server/router.go +++ b/internal/server/router.go @@ -24,6 +24,7 @@ func (srv *server) ListenToRequests() { mux.HandleFunc("GET /", h.MainPage) mux.HandleFunc("POST /answer", h.HandleAnswer) mux.HandleFunc("GET /next-question", h.HandleNextQuestion) + mux.HandleFunc("GET /mixed", h.HandleMixedUbung) // mux.HandleFunc("POST /login", h.HandleLogin) // mux.HandleFunc("POST /signup", h.HandleSignup) |