diff options
author | GrailFinder <wohilas@gmail.com> | 2024-04-15 09:55:08 +0300 |
---|---|---|
committer | GrailFinder <wohilas@gmail.com> | 2024-04-15 09:55:08 +0300 |
commit | ac70f43c3e52e35195353c73af5687b8286ff581 (patch) | |
tree | 877d336d144f7090ff1d13cfecb6e70c072e52eb /internal | |
parent | f71a43e1a4cf2fba8a479842d0a61e24017cd87b (diff) |
Feat: update method on burn_time
Diffstat (limited to 'internal')
-rw-r--r-- | internal/database/repos/action.go | 15 | ||||
-rw-r--r-- | internal/handlers/main.go | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/internal/database/repos/action.go b/internal/database/repos/action.go index 31018b7..6024dd5 100644 --- a/internal/database/repos/action.go +++ b/internal/database/repos/action.go @@ -6,6 +6,7 @@ type ActionRepo interface { DBActionCreate(req *models.Action) error DBActionList(username string) ([]models.Action, error) DBActionDone(name string) error + DBActionsToReset() error } func (p *Provider) DBActionCreate(req *models.Action) error { @@ -26,5 +27,19 @@ func (p *Provider) DBActionList(username string) ([]models.Action, error) { func (p *Provider) DBActionDone(name string) error { // should reset at burn time + stmt := "UPDATE action SET done=true WHERE name=$1;" + _, err := p.db.Exec(stmt, name) + return err +} + +func (p *Provider) DBActionsToReset() error { + stmts := []string{`UPDATE action SET done=false WHERE username IN (SELECT username FROM user_score WHERE burn_time < NOW());`, + `UPDATE user_score SET burn_time=burn_time + INTERVAL '24 hours' WHERE burn_time < NOW();`} + for _, s := range stmts { + if _, err := p.db.Exec(s); err != nil { + // rollback + return err + } + } return nil } diff --git a/internal/handlers/main.go b/internal/handlers/main.go index cb872f0..d779f42 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -131,7 +131,6 @@ func (h *Handlers) UserScoreWithActionsByUsername( if err != nil { return nil, err } - list, err := h.repo.DBActionList("test") if err != nil { return nil, err |