From 8b2e4f3ad2cbff4c521ecfa1466bf25c208af587 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sun, 6 Apr 2025 09:49:42 +0300 Subject: feat: add flexible limit to DBListMixed and new DBGetQuestionsByMixedID --- internal/database/repos/questions.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/database/repos/questions.go b/internal/database/repos/questions.go index daf7e16..4e8ea1e 100644 --- a/internal/database/repos/questions.go +++ b/internal/database/repos/questions.go @@ -1,11 +1,15 @@ 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) - DBGetFirst10MixedUbungs() ([]*models.MixedUbung, error) + DBListMixed(limit uint32) ([]models.MixedUbung, error) + DBGetQuestionsByMixedID(id string) ([]models.Question, error) // implement; ai! } func (p *Provider) DBGetMixedUbung(id uint32) (*models.MixedUbung, error) { @@ -17,9 +21,13 @@ 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") +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 } -- cgit v1.2.3