go-common/app/admin/main/member/http/monitor.go

61 lines
1.0 KiB
Go
Raw Normal View History

2019-04-22 10:49:16 +00:00
package http
import (
"go-common/app/admin/main/member/model"
bm "go-common/library/net/http/blademaster"
)
func monitors(ctx *bm.Context) {
arg := &model.ArgMonitor{}
if err := ctx.Bind(arg); err != nil {
return
}
if arg.Pn <= 0 {
arg.Pn = 1
}
if arg.Ps <= 0 {
arg.Ps = 10
}
mns, total, err := svc.Monitors(ctx, arg)
if err != nil {
ctx.JSON(nil, err)
return
}
res := map[string]interface{}{
"monitors": mns,
"page": map[string]int{
"num": arg.Pn,
"size": arg.Ps,
"total": total,
},
}
ctx.JSON(res, nil)
}
func addMonitor(ctx *bm.Context) {
arg := &model.ArgAddMonitor{}
if err := ctx.Bind(arg); err != nil {
return
}
arg.OperatorID = operatorID(ctx)
ctx.JSON(nil, svc.AddMonitor(ctx, arg))
}
func delMonitor(ctx *bm.Context) {
arg := &model.ArgDelMonitor{}
if err := ctx.Bind(arg); err != nil {
return
}
arg.OperatorID = operatorID(ctx)
ctx.JSON(nil, svc.DelMonitor(ctx, arg))
}
func operatorID(ctx *bm.Context) int64 {
uidI, ok := ctx.Get("uid")
if !ok {
return 0
}
uid, _ := uidI.(int64)
return uid
}