summaryrefslogtreecommitdiff
path: root/internal/handlers/main.go
diff options
context:
space:
mode:
authorGrail Finder (aider) <wohilas@gmail.com>2025-04-05 18:16:11 +0300
committerGrail Finder (aider) <wohilas@gmail.com>2025-04-05 18:16:11 +0300
commitd93fe83d44a5ad547a66e2e08db9503fd05e6c00 (patch)
treee00601e950db232a971b2e0c41fc20bee8e089fd /internal/handlers/main.go
parentb8616490acd715433458da8641f9f4a70cb1c1c0 (diff)
fix: properly increment question ID on next button press
Diffstat (limited to 'internal/handlers/main.go')
-rw-r--r--internal/handlers/main.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/internal/handlers/main.go b/internal/handlers/main.go
index 3524241..b3b1810 100644
--- a/internal/handlers/main.go
+++ b/internal/handlers/main.go
@@ -115,8 +115,12 @@ func getCorrectOption(q *models.Question) string {
func (h *Handlers) HandleNextQuestion(w http.ResponseWriter, r *http.Request) {
currentID := r.URL.Query().Get("current_id")
- nextID, _ := strconv.Atoi(currentID)
- nextID++
+ 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 {
@@ -144,12 +148,6 @@ func (h *Handlers) renderQuestion(w http.ResponseWriter, question *models.Questi
if err != nil {
h.log.Error("failed to render template", "error", err)
}
- question, err = h.repo.DBGetQuestion("1")
- if err != nil {
- h.log.Error("failed to get question", "error", err)
- abortWithError(w, "Question not found")
- return
- }
}