go-mcm/model/note.go

55 lines
1.1 KiB
Go

package model
import (
"encoding/json"
"git.jojodev.com/Minecraft/go-mcm/internal"
"git.jojodev.com/Minecraft/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"`
model *Model `json:"-"`
}
func (q *Model) Note(builder *django.Builder) ([]*Note, error) {
endpoint := q.queryEndpoint("note", builder.QueryString())
notes := make([]*Note, 0)
resp, err := internal.ResponseGet(endpoint)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &notes)
if err != nil {
return nil, err
}
for _, note := range notes {
note.model = q
}
return notes, nil
}
func (n *Note) Save() (*internal.Status, error) {
endpoint := n.model.endpoint("note")
return internal.ResponseStatus(endpoint, n.model.Values(n))
}