summaryrefslogtreecommitdiff
path: root/internal/database/repos/questions.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/database/repos/questions.go')
-rw-r--r--internal/database/repos/questions.go39
1 files changed, 38 insertions, 1 deletions
diff --git a/internal/database/repos/questions.go b/internal/database/repos/questions.go
index d9978a4..9d0396e 100644
--- a/internal/database/repos/questions.go
+++ b/internal/database/repos/questions.go
@@ -1,9 +1,46 @@
package repos
-import "demoon/internal/models"
+import (
+ "demoon/internal/models"
+ "fmt"
+)
type QuestionsRepo interface {
DBGetQuestion(id string) (*models.Question, error)
+ DBGetMixedUbung(id uint32) (*models.MixedUbung, error)
+ DBListMixed(limit uint32) ([]models.MixedUbung, error)
+ DBGetQuestionsByMixedID(id string) ([]models.Question, error)
+}
+
+func (p *Provider) DBGetMixedUbung(id uint32) (*models.MixedUbung, error) {
+ var ubung models.MixedUbung
+ err := p.db.Get(&ubung, "SELECT * FROM Table_Mixed WHERE mixedid = ?", id)
+ if err != nil {
+ return nil, err
+ }
+ return &ubung, nil
+}
+
+func (p *Provider) DBListMixed(limit uint32) ([]models.MixedUbung, error) {
+ var ubungs []models.MixedUbung
+ query := "SELECT * FROM Table_Mixed ORDER BY MixedID"
+ if limit > 0 {
+ query = fmt.Sprintf("SELECT * FROM Table_Mixed ORDER BY MixedID LIMIT %d", limit)
+ }
+ err := p.db.Select(&ubungs, query)
+ if err != nil {
+ return nil, err
+ }
+ return ubungs, nil
+}
+
+func (p *Provider) DBGetQuestionsByMixedID(id string) ([]models.Question, error) {
+ var questions []models.Question
+ err := p.db.Select(&questions, "SELECT * FROM questions WHERE mixed_id = ? ORDER BY id", id)
+ if err != nil {
+ return nil, err
+ }
+ return questions, nil
}
func (p *Provider) DBGetQuestion(id string) (*models.Question, error) {