-
Notifications
You must be signed in to change notification settings - Fork 72
/
keyword.go
124 lines (101 loc) · 2.52 KB
/
keyword.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package wrobot
import (
"github.com/gin-gonic/gin"
"github.com/opentdp/wrest-chat/dbase/keyword"
"github.com/opentdp/wrest-chat/wclient/robot"
)
type Keyword struct{}
// @Summary 关键字列表
// @Produce json
// @Tags BOT::关键字
// @Param body body keyword.FetchAllParam true "获取关键字列表参数"
// @Success 200 {array} tables.Keyword
// @Router /bot/keyword/list [post]
func (*Keyword) list(c *gin.Context) {
var rq *keyword.FetchAllParam
if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}
if lst, err := keyword.FetchAll(rq); err == nil {
c.Set("Payload", lst)
} else {
c.Set("Error", err)
}
}
// @Summary 获取关键字
// @Produce json
// @Tags BOT::关键字
// @Param body body keyword.FetchParam true "获取关键字参数"
// @Success 200 {object} tables.Keyword
// @Router /bot/keyword/detail [post]
func (*Keyword) detail(c *gin.Context) {
var rq *keyword.FetchParam
if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}
if res, err := keyword.Fetch(rq); err == nil {
c.Set("Payload", res)
} else {
c.Set("Error", err)
}
}
// @Summary 添加关键字
// @Produce json
// @Tags BOT::关键字
// @Param body body keyword.CreateParam true "添加关键字参数"
// @Success 200
// @Router /bot/keyword/create [post]
func (*Keyword) create(c *gin.Context) {
var rq *keyword.CreateParam
if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}
if id, err := keyword.Create(rq); err == nil {
c.Set("Message", "添加成功")
c.Set("Payload", id)
robot.Reset()
} else {
c.Set("Error", err)
}
}
// @Summary 修改关键字
// @Produce json
// @Tags BOT::关键字
// @Param body body keyword.UpdateParam true "修改关键字参数"
// @Success 200
// @Router /bot/keyword/update [post]
func (*Keyword) update(c *gin.Context) {
var rq *keyword.UpdateParam
if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}
if err := keyword.Update(rq); err == nil {
c.Set("Message", "更新成功")
robot.Reset()
} else {
c.Set("Error", err)
}
}
// @Summary 删除关键字
// @Produce json
// @Tags BOT::关键字
// @Param body body keyword.DeleteParam true "删除关键字参数"
// @Success 200
// @Router /bot/keyword/delete [post]
func (*Keyword) delete(c *gin.Context) {
var rq *keyword.DeleteParam
if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}
if err := keyword.Delete(rq); err == nil {
c.Set("Message", "删除成功")
robot.Reset()
} else {
c.Set("Error", err)
}
}