summaryrefslogtreecommitdiff
path: root/internal/database/repos/action.go
blob: 31018b7c11e9f33972f0f40daa805dc4ce0f3152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}