go-mcm/model/ticket.go

68 lines
1.3 KiB
Go

package model
import (
"encoding/json"
"go.etztech.xyz/go-mcm/internal"
"go.etztech.xyz/go-mcm/model/django"
)
type Priority string
const (
PriorityLow Priority = "L"
PriorityMedium Priority = "M"
PriorityHigh Priority = "H"
)
type World string
const (
WorldOverworld World = "O"
WorldNether World = "N"
WorldTheEnd World = "E"
)
type Ticket struct {
ID int64 `json:"id"`
PlayerID int64 `json:"player_id"`
Message string `json:"message"`
Priority Priority `json:"priority"`
StaffID int64 `json:"staff_id"`
Resolved bool `json:"resolved"`
World World `json:"world"`
X string `json:"x"`
Y string `json:"Y"`
Z string `json:"Z"`
Date string `json:"date"`
Link string `json:"link"`
model *Model `json:"-"`
}
func (q *Model) Ticket(builder *django.Builder) ([]*Ticket, error) {
endpoint := q.queryEndpoint("ticket", builder.QueryString())
tickets := make([]*Ticket, 0)
resp, err := internal.ResponseGet(endpoint)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &tickets)
if err != nil {
return nil, err
}
for _, ticket := range tickets {
ticket.model = q
}
return tickets, nil
}
func (t *Ticket) Save() (*internal.Status, error) {
endpoint := t.model.endpoint("ticket")
return internal.ResponseStatus(endpoint, t.model.Values(t))
}