summaryrefslogtreecommitdiff
path: root/internal/database
diff options
context:
space:
mode:
Diffstat (limited to 'internal/database')
-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
}