30 lines
609 B
Go
30 lines
609 B
Go
package mood
|
|
|
|
import (
|
|
"time"
|
|
|
|
"code.chrissexton.org/cws/happy/db"
|
|
"code.chrissexton.org/cws/happy/user"
|
|
)
|
|
|
|
type Mood struct {
|
|
db *db.Database
|
|
}
|
|
|
|
func New(db *db.Database) *Mood {
|
|
return &Mood{db}
|
|
}
|
|
|
|
type GetMoodsResponse struct {
|
|
CategoryID int64 `db:"category_id"`
|
|
CategoryName string `db:"category_name"`
|
|
Key string
|
|
Value int64
|
|
}
|
|
|
|
func (m *Mood) RecordMood(mood GetMoodsResponse, who user.User) error {
|
|
q := `insert into moods (user_id,mood_category_id,value,time) values (?,?,?,?)`
|
|
_, err := m.db.Exec(q, who.ID, mood.CategoryID, mood.Value, time.Now().Unix())
|
|
return err
|
|
}
|