go-mcm/model/note.go

55 lines
1.1 KiB
Go
Raw Normal View History

2019-10-02 19:03:23 +00:00
package model
import (
"encoding/json"
2019-10-03 20:22:22 +00:00
"go.etztech.xyz/go-mcm/internal"
2019-10-02 19:03:23 +00:00
"go.etztech.xyz/go-mcm/model/django"
)
type Importance string
const (
ImportanceLow Importance = "L"
ImportanceMedium Importance = "M"
ImportanceHigh Importance = "H"
)
type Note struct {
ID int64 `json:"id"`
PlayerID int64 `json:"player_id"`
Message string `json:"message"`
Importance Importance `json:"importance"`
StaffID int64 `json:"staff_id"`
Date string `json:"date"`
Link string `json:"link"`
2019-11-24 21:20:07 +00:00
model *Model `json:"-"`
2019-10-02 19:03:23 +00:00
}
2019-10-03 20:22:22 +00:00
func (q *Model) Note(builder *django.Builder) ([]*Note, error) {
2019-11-24 21:20:07 +00:00
endpoint := q.queryEndpoint("note", builder.QueryString())
2019-10-02 19:03:23 +00:00
notes := make([]*Note, 0)
2019-10-03 20:22:22 +00:00
resp, err := internal.ResponseGet(endpoint)
2019-10-02 19:03:23 +00:00
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &notes)
if err != nil {
return nil, err
}
2019-11-24 21:20:07 +00:00
for _, note := range notes {
note.model = q
}
2019-10-02 19:03:23 +00:00
return notes, nil
}
2019-11-24 21:20:07 +00:00
func (n *Note) Save() (*internal.Status, error) {
endpoint := n.model.endpoint("note")
return internal.ResponseStatus(endpoint, n.model.Values(n))
}