summaryrefslogtreecommitdiff
path: root/internal/database/repos/action.go
diff options
context:
space:
mode:
authorGrailFinder <wohilas@gmail.com>2024-04-15 09:55:08 +0300
committerGrailFinder <wohilas@gmail.com>2024-04-15 09:55:08 +0300
commitac70f43c3e52e35195353c73af5687b8286ff581 (patch)
tree877d336d144f7090ff1d13cfecb6e70c072e52eb /internal/database/repos/action.go
parentf71a43e1a4cf2fba8a479842d0a61e24017cd87b (diff)
Feat: update method on burn_time
Diffstat (limited to 'internal/database/repos/action.go')
-rw-r--r--internal/database/repos/action.go15
1 files changed, 15 insertions, 0 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
}