diff options
author | Grail Finder <wohilas@gmail.com> | 2025-04-06 10:04:22 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2025-04-06 10:04:22 +0300 |
commit | 1e5faf9b609fa230d763bccdd8520441c5498a15 (patch) | |
tree | 17a92182b49f1222b377fb009a9eff70a84b6a35 | |
parent | 95c3ebfaf9fdb1e65e3dfaef177e4b6d20344009 (diff) |
-rw-r--r-- | components/index.html | 4 | ||||
-rw-r--r-- | components/question.html | 75 | ||||
-rw-r--r-- | demoon.db | bin | 1544192 -> 1564672 bytes | |||
-rw-r--r-- | internal/database/repos/main.go | 3 | ||||
-rw-r--r-- | internal/handlers/main.go | 2 | ||||
-rw-r--r-- | internal/models/models.go | 6 |
6 files changed, 86 insertions, 4 deletions
diff --git a/components/index.html b/components/index.html index b8b126d..816fd21 100644 --- a/components/index.html +++ b/components/index.html @@ -13,13 +13,15 @@ <h1>Mixed Übungen</h1> <div class="ubung-list"> {{range .}} + <p> <button class="ubung-button" - hx-get="/question?mixed_id={{.ID}}" + hx-get="/mixed?id={{.ID}}" hx-target="#ancestor" hx-swap="outerHTML"> {{.Name}} (Level {{.LevelID}}) </button> + </p> {{end}} </div> <div id="ancestor"></div> diff --git a/components/question.html b/components/question.html new file mode 100644 index 0000000..ef4618b --- /dev/null +++ b/components/question.html @@ -0,0 +1,75 @@ +{{define "question"}} +<div id="question"> + {{if .Requirement}} + <p>{{.Requirement}}</p> + {{end}} + <div class="question-text" data-testid="question"> + {{.Text}} + </div> + <div id="reaction"> + {{if eq .Status 1}} + Correct! + {{end}} + {{if eq .Status 2}} + Wrong. + {{end}} + </div> + <div id="feedback" data-testid="feedback"> + {{if ne .Status 0}} + <div> + {{.Explanation}} + </div> + <button + hx-get="/next-question?current_id={{.ID}}" + hx-target="#ancestor" + hx-swap="outerHTML" + class="next-button" + data-testid="next-button"> + Next Question → + </button> + {{end}} + </div> + <div id="options"> + <button + data-testid="option1" + hx-post="/answer" + hx-vals='{"selected": "0", "question_id": "{{.ID}}"}' + hx-target="#ancestor" + hx-swap="innerHTML" + class="option-button" + > + {{.Option1}} + </button> + <button + data-testid="option2" + hx-post="/answer" + hx-vals='{"selected": "1", "question_id": "{{.ID}}"}' + hx-target="#ancestor" + hx-swap="innerHTML" + class="option-button" + > + {{.Option2}} + </button> + <button + data-testid="option3" + hx-post="/answer" + hx-vals='{"selected": "2", "question_id": "{{.ID}}"}' + hx-target="#ancestor" + hx-swap="innerHTML" + class="option-button" + > + {{.Option3}} + </button> + <button + data-testid="option4" + hx-post="/answer" + hx-vals='{"selected": "3", "question_id": "{{.ID}}"}' + hx-target="#ancestor" + hx-swap="innerHTML" + class="option-button" + > + {{.Option4}} + </button> + </div> +</div> +{{end}} Binary files differdiff --git a/internal/database/repos/main.go b/internal/database/repos/main.go index f6835c7..e49d303 100644 --- a/internal/database/repos/main.go +++ b/internal/database/repos/main.go @@ -2,12 +2,11 @@ package repos import ( "github.com/jmoiron/sqlx" - "demoon/internal/models" ) type FullRepo interface { DefaultsRepo - DBGetQuestion(id string) (*models.Question, error) + QuestionsRepo } type Provider struct { diff --git a/internal/handlers/main.go b/internal/handlers/main.go index b6ce093..34f37d9 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -171,7 +171,7 @@ func (h *Handlers) renderQuestion(w http.ResponseWriter, question *models.Questi *models.Question } - err = tmpl.ExecuteTemplate(w, "main", question) + err = tmpl.ExecuteTemplate(w, "question", question) if err != nil { h.log.Error("failed to render template", "error", err) } diff --git a/internal/models/models.go b/internal/models/models.go index 8e30a6c..7cef85e 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -15,4 +15,10 @@ type ( ExamID uint32 `db:"exam_id"` MixedID uint32 `db:"mixed_id"` } + MixedUbung struct { + ID uint32 `db:"MixedID"` + Name string `db:"MixedName"` + Status int `db:"MixedStatus"` + LevelID uint32 `db:"LevelID"` + } ) |