/
handler_admin.go
55 lines (47 loc) · 1.15 KB
/
handler_admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package server
import (
"encoding/json"
"io"
"net/url"
"go.uber.org/zap"
"gopkg.in/go-playground/validator.v9"
"github.com/TradeWars/warehouse/types"
)
func (app *App) adminRoutes() []Route {
return []Route{
{
"adminSet",
"POST",
"/store/adminSet",
types.ExampleAdmin(),
types.ExampleStatus(nil, true),
app.adminSet,
},
{
"adminGetList",
"GET",
"/store/adminGetList",
nil,
[]types.Admin{types.ExampleAdmin(), types.ExampleAdmin()},
app.adminGetList,
},
}
}
func (app *App) adminSet(r io.Reader, query url.Values) (status types.Status, err error) {
var admin types.Admin
err = json.NewDecoder(r).Decode(&admin)
if err != nil {
return
}
err = app.validator.Struct(admin)
if err != nil {
return types.NewStatusValidationError(err.(validator.ValidationErrors)), nil
}
logger.Debug("received request adminSet",
zap.Any("admin", admin))
return types.NewStatus(nil, true, ""), app.store.AdminSetLevel(admin.PlayerID, *admin.Level)
}
func (app *App) adminGetList(r io.Reader, query url.Values) (status types.Status, err error) {
list, err := app.store.AdminGetList()
return types.NewStatus(list, true, ""), err
}