From f71a43e1a4cf2fba8a479842d0a61e24017cd87b Mon Sep 17 00:00:00 2001 From: GrailFinder Date: Sun, 14 Apr 2024 09:11:15 +0300 Subject: Feat: db methods and their usage --- internal/database/repos/action.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 internal/database/repos/action.go (limited to 'internal/database/repos/action.go') diff --git a/internal/database/repos/action.go b/internal/database/repos/action.go new file mode 100644 index 0000000..31018b7 --- /dev/null +++ b/internal/database/repos/action.go @@ -0,0 +1,30 @@ +package repos + +import "apjournal/internal/models" + +type ActionRepo interface { + DBActionCreate(req *models.Action) error + DBActionList(username string) ([]models.Action, error) + DBActionDone(name string) error +} + +func (p *Provider) DBActionCreate(req *models.Action) error { + _, err := p.db.NamedExec(` + INSERT INTO action(username, name, magnitude, repeatable, type, done) + VALUES (:username, :name, :magnitude, :repeatable, :type, :done);`, req) + return err +} + +func (p *Provider) DBActionList(username string) ([]models.Action, error) { + resp := []models.Action{} + query := "SELECT * FROM action WHERE username=$1;" + if err := p.db.Select(&resp, query, username); err != nil { + return nil, err + } + return resp, nil +} + +func (p *Provider) DBActionDone(name string) error { + // should reset at burn time + return nil +} -- cgit v1.2.3