summaryrefslogtreecommitdiff
path: root/internal/handlers
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-04-19 07:21:49 +0300
committerGrail Finder <wohilas@gmail.com>2025-04-19 07:21:49 +0300
commit769589c59b9c7c29b11060fe19cec9f0f1ae9603 (patch)
treeef434e582e164f62a4fd168fd2f1918ab875a416 /internal/handlers
parent1e5faf9b609fa230d763bccdd8520441c5498a15 (diff)
Feat: get next question in mixed groupHEADmaster
Diffstat (limited to 'internal/handlers')
-rw-r--r--internal/handlers/main.go37
1 files changed, 31 insertions, 6 deletions
diff --git a/internal/handlers/main.go b/internal/handlers/main.go
index 34f37d9..79d92f4 100644
--- a/internal/handlers/main.go
+++ b/internal/handlers/main.go
@@ -92,7 +92,7 @@ func (h *Handlers) HandleAnswer(w http.ResponseWriter, r *http.Request) {
// Execute template with question data including status
w.Header().Set("Content-Type", "text/html")
- err = tmpl.ExecuteTemplate(w, "main", question)
+ err = tmpl.ExecuteTemplate(w, "question", question)
if err != nil {
h.log.Error("failed to render feedback template", "error", err)
}
@@ -120,8 +120,13 @@ func (h *Handlers) HandleMixedUbung(w http.ResponseWriter, r *http.Request) {
abortWithError(w, "Missing exercise ID")
return
}
-
- questions, err := h.repo.DBGetQuestionsByMixedID(mixedID)
+ mid, err := strconv.ParseUint(mixedID, 10, 64)
+ if err != nil {
+ h.log.Error("failed to convert mixedid", "mixed_id", mixedID)
+ abortWithError(w, "failed to convert mixed_id")
+ return
+ }
+ questions, err := h.repo.DBGetQuestionsByMixedID(uint32(mid))
if err != nil {
h.log.Error("failed to get questions for mixed exercise", "error", err, "mixed_id", mixedID)
abortWithError(w, "Failed to load exercise")
@@ -140,22 +145,42 @@ func (h *Handlers) HandleMixedUbung(w http.ResponseWriter, r *http.Request) {
func (h *Handlers) HandleNextQuestion(w http.ResponseWriter, r *http.Request) {
currentID := r.URL.Query().Get("current_id")
+ mixedID := r.FormValue("mixed_id")
currID, err := strconv.Atoi(currentID)
if err != nil {
h.log.Error("invalid current question ID", "error", err, "current_id", currentID)
currID = 0 // Start from first question if invalid ID
}
nextID := currID + 1
-
question, err := h.repo.DBGetQuestion(strconv.Itoa(nextID))
if err != nil {
h.log.Error("failed to get next question", "error", err)
abortWithError(w, "No more questions")
return
}
-
+ if mixedID != "" {
+ mid, err := strconv.ParseUint(mixedID, 10, 64)
+ if err != nil {
+ h.log.Error("failed to convert mixedid", "mixed_id", mixedID)
+ abortWithError(w, "failed to convert mixed_id")
+ return
+ }
+ qList, err := h.repo.DBGetQuestionsByMixedID(uint32(mid))
+ if err != nil {
+ h.log.Error("failed to retrieve questions", "mixed_id", mid)
+ abortWithError(w, "failed to retrieve questions")
+ return
+ }
+ for i, q := range qList {
+ if q.ID > uint32(nextID) {
+ // load next question
+ question = &q
+ h.log.Error("returning question from mixed group", "#", i)
+ break
+ }
+ }
+ }
h.log.Debug("returning new question", "q", question)
-
h.renderQuestion(w, question)
}