summaryrefslogtreecommitdiff
path: root/internal/models/models.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-03-29 11:12:53 +0300
committerGrail Finder <wohilas@gmail.com>2025-03-29 11:12:53 +0300
commit3921db6166e2da895257496bb76dd115556699d3 (patch)
tree1be4f739121761085f69cb7706c60dbbe98a93e9 /internal/models/models.go
init
Diffstat (limited to 'internal/models/models.go')
-rw-r--r--internal/models/models.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/models/models.go b/internal/models/models.go
new file mode 100644
index 0000000..5bc120b
--- /dev/null
+++ b/internal/models/models.go
@@ -0,0 +1,45 @@
+package models
+
+import "time"
+
+type ActionType string
+
+const (
+ ActionTypePlus ActionType = "ActionTypePlus"
+ ActionTypeMinus ActionType = "ActionTypeMinus"
+)
+
+type (
+ UserScore struct {
+ ID uint32 `db:"id"`
+ Username string `db:"username"`
+ Password string `db:"password"`
+ Actions []Action
+ Recommendations []Action
+ BurnTime time.Time `db:"burn_time"`
+ Score int8 `db:"score"`
+ CreatedAt time.Time `db:"created_at"`
+ }
+ Action struct {
+ ID uint32 `db:"id"`
+ Name string `db:"name"`
+ Magnitude uint8 `db:"magnitude"`
+ Repeatable bool `db:"repeatable"`
+ Type ActionType `db:"type"`
+ Done bool `db:"done"`
+ Username string `db:"username"`
+ CreatedAt time.Time `db:"created_at"`
+ }
+)
+
+func (us *UserScore) UpdateScore(act *Action) {
+ switch act.Type {
+ case ActionTypePlus:
+ us.Score += int8(act.Magnitude)
+ if !act.Repeatable {
+ act.Done = true
+ }
+ case ActionTypeMinus:
+ us.Score -= int8(act.Magnitude)
+ }
+}