-
Notifications
You must be signed in to change notification settings - Fork 96
/
option.go
102 lines (95 loc) · 2.46 KB
/
option.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package system
import (
"github.com/douyu/juno/internal/pkg/packages/contrib/output"
"github.com/douyu/juno/internal/pkg/service/system"
"github.com/douyu/juno/pkg/model/db"
"github.com/douyu/juno/pkg/model/view"
"github.com/labstack/echo/v4"
)
// 可用区信息
func OptionInfo(c echo.Context) error {
var (
err error
info db.Option
)
reqModel := view.ReqOptionInfo{}
err = c.Bind(&reqModel)
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
info, err = system.System.GetOptionInfo(db.Option{
Id: reqModel.Id,
OptionTitle: reqModel.OptionTitle,
})
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
return output.JSON(c, output.MsgOk, "success", info)
}
// 可用区列表
func OptionList(c echo.Context) error {
var (
err error
)
reqModel := view.ReqOptionList{}
err = c.Bind(&reqModel)
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
list, pagination, err := system.System.GetOptionList(db.Option{}, reqModel.CurrentPage, reqModel.PageSize, "update_time desc")
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
return output.JSON(c, output.MsgOk, "success", map[string]interface{}{
"pagination": pagination,
"list": list,
})
}
// 只有可用区的创建功能
func OptionCreate(c echo.Context) error {
var (
err error
)
reqModel := view.ReqOptionCreate{}
err = c.Bind(&reqModel)
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
err = system.System.CreateOption(reqModel.Option, &db.User{})
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
return output.JSON(c, output.MsgOk, "success")
}
// 只有可用区的更新功能
func OptionUpdate(c echo.Context) error {
var (
err error
)
reqModel := view.ReqOptionUpdate{}
err = c.Bind(&reqModel)
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
err = system.System.UpdateOption(reqModel.Option, &db.User{})
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
return output.JSON(c, output.MsgOk, "success")
}
// 只有可用区的删除功能
func OptionDelete(c echo.Context) error {
var (
err error
)
reqModel := view.ReqOptionDelete{}
err = c.Bind(&reqModel)
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
err = system.System.DeleteOption(reqModel.Option, &db.User{})
if err != nil {
return output.JSON(c, output.MsgErr, err.Error())
}
return output.JSON(c, output.MsgOk, "success")
}