@@ -6,7 +6,6 @@ package service
6
6
7
7
import (
8
8
"context"
9
- "fmt"
10
9
"strings"
11
10
"time"
12
11
@@ -40,23 +39,19 @@ func NewTemplateService(conf *config.PostarAdminConfig, templateStore TemplateSt
40
39
41
40
func (dts * defaultTemplateService ) checkCreateTemplateParams (template * model.Template ) error {
42
41
if template .AccountID <= 0 {
43
- err := errors .New ("template.AccountID <= 0" )
44
- return errors .BadRequest (err , errors .WithMsg ("模板绑定的账号编号非法" ))
42
+ return errors .BadRequest ("模板绑定的账号编号需要大于 0" )
45
43
}
46
44
47
45
if strings .TrimSpace (template .Name ) == "" {
48
- err := errors .New ("trim template.Name == ''" )
49
- return errors .BadRequest (err , errors .WithMsg ("模板名称不能为空" ))
46
+ return errors .BadRequest ("模板名称不能为空" )
50
47
}
51
48
52
49
if strings .TrimSpace (template .Email .Subject ) == "" {
53
- err := errors .New ("trim template.Email.Subject == ''" )
54
- return errors .BadRequest (err , errors .WithMsg ("模板邮件主题不能为空" ))
50
+ return errors .BadRequest ("模板邮件主题不能为空" )
55
51
}
56
52
57
53
if ! template .Email .ContentType .Valid () {
58
- err := fmt .Errorf ("template.Email.ContentType %d not valid" , template .Email .ContentType )
59
- return errors .BadRequest (err , errors .WithMsg ("模板邮件内容类型无效" ))
54
+ return errors .BadRequest ("模板邮件内容类型 %d 无效" , template .Email .ContentType )
60
55
}
61
56
62
57
return nil
@@ -81,33 +76,27 @@ func (dts *defaultTemplateService) CreateTemplate(ctx context.Context, spaceID i
81
76
82
77
func (dts * defaultTemplateService ) checkUpdateTemplateParams (template * model.Template ) error {
83
78
if template .ID <= 0 {
84
- err := errors .New ("template.ID <= 0" )
85
- return errors .BadRequest (err , errors .WithMsg ("模板编号非法" ))
79
+ return errors .BadRequest ("模板编号需要大于 0" )
86
80
}
87
81
88
82
if template .AccountID <= 0 {
89
- err := errors .New ("template.AccountID <= 0" )
90
- return errors .BadRequest (err , errors .WithMsg ("模板绑定的账号编号非法" ))
83
+ return errors .BadRequest ("模板绑定的账号编号需要大于 0" )
91
84
}
92
85
93
86
if strings .TrimSpace (template .Name ) == "" {
94
- err := errors .New ("trim template.Name == ''" )
95
- return errors .BadRequest (err , errors .WithMsg ("模板名称不能为空" ))
87
+ return errors .BadRequest ("模板名称不能为空" )
96
88
}
97
89
98
90
if strings .TrimSpace (template .Email .Subject ) == "" {
99
- err := errors .New ("trim template.Email.Subject == ''" )
100
- return errors .BadRequest (err , errors .WithMsg ("模板邮件主题不能为空" ))
91
+ return errors .BadRequest ("模板邮件主题不能为空" )
101
92
}
102
93
103
94
if template .Email .ContentType > 0 && ! template .Email .ContentType .Valid () {
104
- err := fmt .Errorf ("template.Email.Content.Type %d not valid" , template .Email .ContentType )
105
- return errors .BadRequest (err , errors .WithMsg ("模板邮件内容类型无效" ))
95
+ return errors .BadRequest ("模板邮件内容类型 %d 无效" , template .Email .ContentType )
106
96
}
107
97
108
98
if template .State > 0 && ! template .State .Valid () {
109
- err := fmt .Errorf ("template.State %d not valid" , template .State )
110
- return errors .BadRequest (err , errors .WithMsg ("模板状态无效" ))
99
+ return errors .BadRequest ("模板状态 %d 无效" , template .State )
111
100
}
112
101
113
102
return nil
@@ -130,8 +119,7 @@ func (dts *defaultTemplateService) UpdateTemplate(ctx context.Context, spaceID i
130
119
131
120
func (dts * defaultTemplateService ) checkGetTemplateParams (templateID int64 ) error {
132
121
if templateID <= 0 {
133
- err := fmt .Errorf ("templateID %d <= 0" , templateID )
134
- return errors .BadRequest (err , errors .WithMsg ("模板编号非法" ))
122
+ return errors .BadRequest ("模板编号需要大于 0" )
135
123
}
136
124
137
125
return nil
@@ -150,23 +138,19 @@ func (dts *defaultTemplateService) GetTemplate(ctx context.Context, spaceID int3
150
138
151
139
func (dts * defaultTemplateService ) checkListTemplatesParams (pageSize int32 , filter * model.ListTemplatesFilter ) error {
152
140
if pageSize < minPageSize || pageSize > maxPageSize {
153
- err := fmt .Errorf ("pageSize %d not in [%d, %d]" , pageSize , minPageSize , maxPageSize )
154
- return errors .BadRequest (err , errors .WithMsg ("分页大小需要位于区间 [%d, %d] 内" , minPageSize , maxPageSize ))
141
+ return errors .BadRequest ("分页大小 %d 需要位于区间 [%d, %d] 内" , pageSize , minPageSize , maxPageSize )
155
142
}
156
143
157
144
if filter .AccountID < 0 {
158
- err := fmt .Errorf ("filter.AccountID %d < 0" , filter .AccountID )
159
- return errors .BadRequest (err , errors .WithMsg ("过滤的账号编号非法" ))
145
+ return errors .BadRequest ("账号编号不能为负数" )
160
146
}
161
147
162
148
if filter .TemplateID < 0 {
163
- err := fmt .Errorf ("filter.TemplateID %d < 0" , filter .TemplateID )
164
- return errors .BadRequest (err , errors .WithMsg ("过滤的模板编号非法" ))
149
+ return errors .BadRequest ("模板编号不能为负数" )
165
150
}
166
151
167
152
if filter .TemplateState > 0 && ! filter .TemplateState .Valid () {
168
- err := fmt .Errorf ("filter.TemplateState %d not valid" , filter .TemplateState )
169
- return errors .BadRequest (err , errors .WithMsg ("过滤的模板状态非法" ))
153
+ return errors .BadRequest ("模板状态 %d 无效" , filter .TemplateState )
170
154
}
171
155
172
156
return nil
@@ -198,8 +182,7 @@ func (dts *defaultTemplateService) ListTemplates(ctx context.Context, spaceID in
198
182
199
183
func (dts * defaultTemplateService ) checkDeleteTemplateParams (templateID int64 ) error {
200
184
if templateID <= 0 {
201
- err := fmt .Errorf ("templateID %d <= 0" , templateID )
202
- return errors .BadRequest (err , errors .WithMsg ("模板编号非法" ))
185
+ return errors .BadRequest ("模板编号需要大于 0" )
203
186
}
204
187
205
188
return nil
0 commit comments