summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/database/repos/questions.go10
-rw-r--r--internal/handlers/main.go19
2 files changed, 25 insertions, 4 deletions
diff --git a/internal/database/repos/questions.go b/internal/database/repos/questions.go
index ab5e093..daf7e16 100644
--- a/internal/database/repos/questions.go
+++ b/internal/database/repos/questions.go
@@ -5,6 +5,7 @@ import "demoon/internal/models"
type QuestionsRepo interface {
DBGetQuestion(id string) (*models.Question, error)
DBGetMixedUbung(id uint32) (*models.MixedUbung, error)
+ DBGetFirst10MixedUbungs() ([]*models.MixedUbung, error)
}
func (p *Provider) DBGetMixedUbung(id uint32) (*models.MixedUbung, error) {
@@ -16,6 +17,15 @@ func (p *Provider) DBGetMixedUbung(id uint32) (*models.MixedUbung, error) {
return &ubung, nil
}
+func (p *Provider) DBGetFirst10MixedUbungs() ([]*models.MixedUbung, error) {
+ var ubungs []*models.MixedUbung
+ err := p.db.Select(&ubungs, "SELECT * FROM Table_Mixed ORDER BY MixedID LIMIT 10")
+ if err != nil {
+ return nil, err
+ }
+ return ubungs, nil
+}
+
func (p *Provider) DBGetQuestion(id string) (*models.Question, error) {
var question models.Question
err := p.db.Get(&question, "SELECT * FROM questions WHERE id = ?", id)
diff --git a/internal/handlers/main.go b/internal/handlers/main.go
index 41ff85f..4aa8eca 100644
--- a/internal/handlers/main.go
+++ b/internal/handlers/main.go
@@ -154,11 +154,22 @@ func (h *Handlers) renderQuestion(w http.ResponseWriter, question *models.Questi
}
func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) {
- question, err := h.repo.DBGetQuestion("1")
+ ubungs, err := h.repo.DBGetFirst10MixedUbungs()
if err != nil {
- h.log.Error("failed to get question", "error", err)
- abortWithError(w, "Question not found")
+ h.log.Error("failed to get mixed ubungs", "error", err)
+ abortWithError(w, "Failed to load exercises")
return
}
- h.renderQuestion(w, question)
+
+ tmpl, err := template.ParseGlob("components/*.html")
+ if err != nil {
+ abortWithError(w, err.Error())
+ return
+ }
+
+ w.Header().Set("Content-Type", "text/html")
+ err = tmpl.ExecuteTemplate(w, "main", ubungs)
+ if err != nil {
+ h.log.Error("failed to render template", "error", err)
+ }
}