2019-10-02 19:03:23 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-06-11 06:10:01 +00:00
|
|
|
|
2021-07-13 23:28:16 +00:00
|
|
|
"git.canopymc.net/Etzelia/go-mcm/internal"
|
|
|
|
"git.canopymc.net/Etzelia/go-mcm/model/django"
|
2019-10-02 19:03:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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"`
|
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) Ticket(builder *django.Builder) ([]*Ticket, error) {
|
2019-11-24 21:20:07 +00:00
|
|
|
endpoint := q.queryEndpoint("ticket", builder.QueryString())
|
2019-10-02 19:03:23 +00:00
|
|
|
tickets := make([]*Ticket, 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, &tickets)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-24 21:20:07 +00:00
|
|
|
for _, ticket := range tickets {
|
|
|
|
ticket.model = q
|
|
|
|
}
|
|
|
|
|
2019-10-02 19:03:23 +00:00
|
|
|
return tickets, nil
|
|
|
|
}
|
2019-11-24 21:20:07 +00:00
|
|
|
|
|
|
|
func (t *Ticket) Save() (*internal.Status, error) {
|
|
|
|
endpoint := t.model.endpoint("ticket")
|
|
|
|
return internal.ResponseStatus(endpoint, t.model.Values(t))
|
|
|
|
}
|