2019-10-02 19:03:23 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-06-11 06:10:01 +00:00
|
|
|
|
2019-10-03 20:22:22 +00:00
|
|
|
"go.etztech.xyz/go-mcm/internal"
|
2019-10-02 19:03:23 +00:00
|
|
|
"go.etztech.xyz/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"`
|
2020-06-11 06:10:01 +00:00
|
|
|
Accepted *bool `json:"accepted"`
|
2019-10-02 19:03:23 +00:00
|
|
|
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) Application(builder *django.Builder) ([]*Application, error) {
|
2019-11-24 21:20:07 +00:00
|
|
|
endpoint := q.queryEndpoint("application", builder.QueryString())
|
2019-10-02 19:03:23 +00:00
|
|
|
applications := make([]*Application, 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, &applications)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-24 21:20:07 +00:00
|
|
|
for _, application := range applications {
|
|
|
|
application.model = q
|
|
|
|
}
|
|
|
|
|
2019-10-02 19:03:23 +00:00
|
|
|
return applications, nil
|
|
|
|
}
|
2019-11-24 21:20:07 +00:00
|
|
|
|
|
|
|
func (a *Application) Save() (*internal.Status, error) {
|
|
|
|
endpoint := a.model.endpoint("application")
|
|
|
|
return internal.ResponseStatus(endpoint, a.model.Values(a))
|
|
|
|
}
|