diff options
author | Grail Finder <wohilas@gmail.com> | 2025-04-06 09:49:42 +0300 |
---|---|---|
committer | Grail Finder (aider) <wohilas@gmail.com> | 2025-04-06 09:49:42 +0300 |
commit | 8b2e4f3ad2cbff4c521ecfa1466bf25c208af587 (patch) | |
tree | fc474e114b1f9c16253328422e9e46272dd822d3 | |
parent | ad29977e1ad64439f2dd620849439e40c8b97860 (diff) |
feat: add flexible limit to DBListMixed and new DBGetQuestionsByMixedID
-rw-r--r-- | internal/database/repos/questions.go | 18 |
1 files 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 } |