go-mcm/model/application.go

51 lines
1.3 KiB
Go

package model
import (
"encoding/json"
"git.canopymc.net/Etzelia/go-mcm/internal"
"git.canopymc.net/Etzelia/go-mcm/model/django"
)
type Application struct {
ID int64 `json:"id"`
Username string `json:"username"`
Age int64 `json:"age"`
PlayerType string `json:"player_type"`
EverBanned bool `json:"ever_banned"`
EverBannedExplanation string `json:"ever_banned_explanation"`
Reference string `json:"reference"`
ReadRules string `json:"read_rules"`
Accepted *bool `json:"accepted"`
Date string `json:"date"`
Link string `json:"link"`
model *Model `json:"-"`
}
func (q *Model) Application(builder *django.Builder) ([]*Application, error) {
endpoint := q.queryEndpoint("application", builder.QueryString())
applications := make([]*Application, 0)
resp, err := internal.ResponseGet(endpoint)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &applications)
if err != nil {
return nil, err
}
for _, application := range applications {
application.model = q
}
return applications, nil
}
func (a *Application) Save() (*internal.Status, error) {
endpoint := a.model.endpoint("application")
return internal.ResponseStatus(endpoint, a.model.Values(a))
}