...
|
...
|
@@ -35,15 +35,9 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) |
|
|
// 创建新文章
|
|
|
func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
|
|
// 检查文字数量
|
|
|
wordNum := 0
|
|
|
for i := range req.Section {
|
|
|
num := utf8.RuneCountInString(req.Section[i])
|
|
|
wordNum += num
|
|
|
}
|
|
|
if wordNum >= 1000 {
|
|
|
return nil, xerr.NewErrMsgErr("最多只能输入1000字", err)
|
|
|
err = l.validateTextLimit(req)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsg(err.Error())
|
|
|
}
|
|
|
// 检查发布人
|
|
|
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
|
...
|
...
|
@@ -208,13 +202,6 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR |
|
|
return xerr.NewErrMsgErr("创建文章内容失败", err)
|
|
|
}
|
|
|
}
|
|
|
// 设置保存备份
|
|
|
// backup := newArticle.MakeBackup(newArticle.Author, sectionList)
|
|
|
// backup.Action = "新增"
|
|
|
// _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
|
|
|
// if err != nil {
|
|
|
// return xerr.NewErrMsgErr("创建文章内容失败", err)
|
|
|
// }
|
|
|
return nil
|
|
|
}, true)
|
|
|
if err != nil {
|
...
|
...
|
@@ -226,3 +213,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR |
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// validateTextLimit 验证输入文本长度
|
|
|
func (l *MiniCreateArticleLogic) validateTextLimit(req *types.MiniArticleCreateRequest) error {
|
|
|
wordNum := 0
|
|
|
for i := range req.Section {
|
|
|
num := utf8.RuneCountInString(req.Section[i])
|
|
|
wordNum += num
|
|
|
}
|
|
|
if wordNum > 1000 {
|
|
|
return xerr.NewErrMsg("最多只能输入1000字")
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|