作者 tangxvhui

Merge branch 'dev' into test

@@ -35,15 +35,9 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) @@ -35,15 +35,9 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext)
35 // 创建新文章 35 // 创建新文章
36 func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) { 36 func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
37 var conn = l.svcCtx.DefaultDBConn() 37 var conn = l.svcCtx.DefaultDBConn()
38 -  
39 - // 检查文字数量  
40 - wordNum := 0  
41 - for i := range req.Section {  
42 - num := utf8.RuneCountInString(req.Section[i])  
43 - wordNum += num  
44 - }  
45 - if wordNum >= 1000 {  
46 - return nil, xerr.NewErrMsgErr("最多只能输入1000字", err) 38 + err = l.validateTextLimit(req)
  39 + if err != nil {
  40 + return nil, xerr.NewErrMsg(err.Error())
47 } 41 }
48 // 检查发布人 42 // 检查发布人
49 author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId) 43 author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
@@ -208,13 +202,6 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -208,13 +202,6 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
208 return xerr.NewErrMsgErr("创建文章内容失败", err) 202 return xerr.NewErrMsgErr("创建文章内容失败", err)
209 } 203 }
210 } 204 }
211 - // 设置保存备份  
212 - // backup := newArticle.MakeBackup(newArticle.Author, sectionList)  
213 - // backup.Action = "新增"  
214 - // _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)  
215 - // if err != nil {  
216 - // return xerr.NewErrMsgErr("创建文章内容失败", err)  
217 - // }  
218 return nil 205 return nil
219 }, true) 206 }, true)
220 if err != nil { 207 if err != nil {
@@ -226,3 +213,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -226,3 +213,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
226 } 213 }
227 return 214 return
228 } 215 }
  216 +
  217 +// validateTextLimit 验证输入文本长度
  218 +func (l *MiniCreateArticleLogic) validateTextLimit(req *types.MiniArticleCreateRequest) error {
  219 + wordNum := 0
  220 + for i := range req.Section {
  221 + num := utf8.RuneCountInString(req.Section[i])
  222 + wordNum += num
  223 + }
  224 + if wordNum > 1000 {
  225 + return xerr.NewErrMsg("最多只能输入1000字")
  226 + }
  227 + return nil
  228 +}
@@ -2,11 +2,12 @@ package article @@ -2,11 +2,12 @@ package article
2 2
3 import ( 3 import (
4 "context" 4 "context"
5 - "github.com/jinzhu/copier"  
6 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"  
7 "strconv" 5 "strconv"
8 "unicode/utf8" 6 "unicode/utf8"
9 7
  8 + "github.com/jinzhu/copier"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
  10 +
10 "strings" 11 "strings"
11 12
12 "github.com/samber/lo" 13 "github.com/samber/lo"
@@ -199,7 +200,7 @@ func (l *SystemUpdateArticleLogic) validateTextLimit(req *types.SystemArticleUpd @@ -199,7 +200,7 @@ func (l *SystemUpdateArticleLogic) validateTextLimit(req *types.SystemArticleUpd
199 num := utf8.RuneCountInString(req.Section[i].Content) 200 num := utf8.RuneCountInString(req.Section[i].Content)
200 wordNum += num 201 wordNum += num
201 } 202 }
202 - if wordNum >= 1000 { 203 + if wordNum > 1000 {
203 return xerr.NewErrMsg("最多只能输入1000字") 204 return xerr.NewErrMsg("最多只能输入1000字")
204 } 205 }
205 return nil 206 return nil