-
Notifications
You must be signed in to change notification settings - Fork 79
/
model.go
104 lines (68 loc) · 1.61 KB
/
model.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
package webhook
import (
"errors"
"github.com/opentdp/go-helper/dborm"
"github.com/opentdp/wrest-chat/dbase/tables"
)
// 创建 webhook
type CreateWebhookParam struct {
TargetId string `json:"target_id" binding:"required"`
Remark string `json:"remark"`
}
func Create(data *CreateWebhookParam) (string, error) {
token := generateGUID()
item := &tables.Webhook{
TargetId: data.TargetId,
Token: token,
Remark: data.Remark,
}
result := dborm.Db.Create(item)
return token, result.Error
}
// 获取 webhook
type FetchWebhookParam struct {
Rd uint `json:"rd"`
TargetId string `json:"target_id"`
Token string `json:"token"`
}
func Fetch(data *FetchWebhookParam) (*tables.Webhook, error) {
var item *tables.Webhook
result := dborm.Db.
Where(&tables.Webhook{
Rd: data.Rd,
TargetId: data.TargetId,
Token: data.Token,
}).
First(&item)
if item == nil {
return nil, errors.New("未找到记录")
}
return item, result.Error
}
// 删除 webhook
type DeleteWebhookParam = FetchWebhookParam
func Delete(data *DeleteWebhookParam) error {
var item *tables.Webhook
result := dborm.Db.
Where(&tables.Webhook{
Rd: data.Rd,
TargetId: data.TargetId,
Token: data.Token,
}).
Delete(&item)
return result.Error
}
// 获取 webhook 列表
func FetchAll() ([]*tables.Webhook, error) {
var items []*tables.Webhook
result := dborm.Db.Find(&items)
return items, result.Error
}
// 获取 webhook 总数
func Count() (int64, error) {
var count int64
result := dborm.Db.
Model(&tables.LLModel{}).
Count(&count)
return count, result.Error
}