44 lines
807 B
Go
44 lines
807 B
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"go.etztech.xyz/go-mcm/internal"
|
|
"go.etztech.xyz/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))
|
|
}
|