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 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) } }