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 Results int64
|
|
|
|
|
|
|
|
const (
|
|
|
|
Results10 Results = 10
|
|
|
|
Results25 Results = 25
|
|
|
|
Results50 Results = 50
|
|
|
|
Results100 Results = 100
|
|
|
|
ResultsAll Results = -1
|
|
|
|
)
|
|
|
|
|
|
|
|
type Theme string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ThemesDefault Theme = "DE"
|
|
|
|
ThemesDark Theme = "DA"
|
|
|
|
ThemesSolar Theme = "SO"
|
|
|
|
ThemesSlate Theme = "SL"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserSettings struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
AuthUserID int64 `json:"auth_user_id"`
|
|
|
|
DefaultResults Results `json:"default_results"`
|
|
|
|
DefaultTheme Theme `json:"default_theme"`
|
|
|
|
DefaultTimezone string `json:"default_timezone"`
|
|
|
|
SearchPlayerIP bool `json:"search_player_ip"`
|
|
|
|
ShowTimestampChat bool `json:"show_timestamp_chat"`
|
|
|
|
LastIP string `json:"last_ip"`
|
|
|
|
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) UserSettings(builder *django.Builder) ([]*UserSettings, error) {
|
2019-11-24 21:20:07 +00:00
|
|
|
endpoint := q.queryEndpoint("usersettings", builder.QueryString())
|
2019-10-02 19:03:23 +00:00
|
|
|
userSettingss := make([]*UserSettings, 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, &userSettingss)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-24 21:20:07 +00:00
|
|
|
for _, userSetting := range userSettingss {
|
|
|
|
userSetting.model = q
|
|
|
|
}
|
|
|
|
|
2019-10-02 19:03:23 +00:00
|
|
|
return userSettingss, nil
|
|
|
|
}
|
2019-11-24 21:20:07 +00:00
|
|
|
|
|
|
|
func (u *UserSettings) Save() (*internal.Status, error) {
|
|
|
|
endpoint := u.model.endpoint("usersettings")
|
|
|
|
return internal.ResponseStatus(endpoint, u.model.Values(u))
|
|
|
|
}
|