summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
- }
}