go-mcm/model/ip.go

44 lines
827 B
Go

package model
import (
"encoding/json"
"git.canopymc.net/Etzelia/go-mcm/internal"
"git.canopymc.net/Etzelia/go-mcm/model/django"
)
type IP struct {
ID int64 `json:"id"`
PlayerID int64 `json:"player_id"`
LastUsed string `json:"last_used"`
Link string `json:"link"`
model *Model `json:"-"`
}
func (q *Model) IP(builder *django.Builder) ([]*IP, error) {
endpoint := q.queryEndpoint("ip", builder.QueryString())
ips := make([]*IP, 0)
resp, err := internal.ResponseGet(endpoint)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &ips)
if err != nil {
return nil, err
}
for _, ip := range ips {
ip.model = q
}
return ips, nil
}
func (i *IP) Save() (*internal.Status, error) {
endpoint := i.model.endpoint("ip")
return internal.ResponseStatus(endpoint, i.model.Values(i))
}