summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder (aider) <wohilas@gmail.com>2025-04-05 17:56:09 +0300
committerGrail Finder (aider) <wohilas@gmail.com>2025-04-05 17:56:09 +0300
commitba24de361eb2133d5e014d5796f654c82e6d69cb (patch)
treed62132c1ba98b3533049e5744ca5253248d63504
parent96441a431eaca60b1b798e997608812c8be76598 (diff)
feat: return full Question model in /answer response
-rw-r--r--components/index.html5
-rw-r--r--internal/handlers/main.go13
2 files changed, 17 insertions, 1 deletions
diff --git a/components/index.html b/components/index.html
index d3811b1..31775b0 100644
--- a/components/index.html
+++ b/components/index.html
@@ -17,6 +17,11 @@
{{.Text}}
</div>
<div id="feedback" data-testid="feedback">
+ {{if eq .Status 1}}
+ <div class="feedback">Correct! 🎉</div>
+ {{else if eq .Status 2}}
+ <div class="feedback">Wrong answer! The correct answer was: {{index .Options .CorrectIndex}}</div>
+ {{end}}
{{if ne .Status 0}}
<div>
{{.Explanation}}
diff --git a/internal/handlers/main.go b/internal/handlers/main.go
index 4717f3c..a685b88 100644
--- a/internal/handlers/main.go
+++ b/internal/handlers/main.go
@@ -88,8 +88,19 @@ func (h *Handlers) HandleAnswer(w http.ResponseWriter, r *http.Request) {
feedback = `<div data-testid="feedback" class="feedback">Wrong answer! The correct answer was: ` + getCorrectOption(question) + `</div>`
}
+ // Render feedback section with full question state
+ tmpl, err := template.ParseGlob("components/*.html")
+ if err != nil {
+ abortWithError(w, err.Error())
+ return
+ }
+
+ // Execute template with question data including status
w.Header().Set("Content-Type", "text/html")
- w.Write([]byte(feedback))
+ err = tmpl.ExecuteTemplate(w, "feedback", question)
+ if err != nil {
+ h.log.Error("failed to render feedback template", "error", err)
+ }
}
func getCorrectOption(q *models.Question) string {