-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathgroup.go
66 lines (55 loc) · 1.33 KB
/
group.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
package admin
import (
"jiacrontab/models"
"jiacrontab/pkg/proto"
)
// GetGroupList 获得所有的分组列表
func GetGroupList(ctx *myctx) {
var (
err error
groupList []models.Group
count int64
model = models.DB().Model(&models.Group{})
reqBody GetGroupListReqParams
)
if err = ctx.Valid(&reqBody); err != nil {
ctx.respParamError(err)
return
}
if !ctx.isSuper() {
ctx.respNotAllowed()
return
}
model.Where("name like ?", "%"+reqBody.SearchTxt+"%").Count(&count)
err = model.Where("name like ?", "%"+reqBody.SearchTxt+"%").Offset((reqBody.Page - 1) * reqBody.Pagesize).Order("updated_at desc").Limit(reqBody.Pagesize).Find(&groupList).Error
if err != nil {
ctx.respError(proto.Code_Error, err.Error(), nil)
return
}
ctx.respSucc("", map[string]interface{}{
"list": groupList,
"total": count,
"page": reqBody.Page,
"pagesize": reqBody.Pagesize,
})
}
// EditGroup 编辑分组
func EditGroup(ctx *myctx) {
var (
reqBody EditGroupReqParams
err error
group models.Group
)
if err = ctx.Valid(&reqBody); err != nil {
ctx.respParamError(err)
return
}
group.ID = reqBody.GroupID
group.Name = reqBody.GroupName
if err = group.Save(); err != nil {
ctx.respBasicError(err)
return
}
ctx.pubEvent(group.Name, event_EditGroup, "", reqBody)
ctx.respSucc("", nil)
}