作者 tangxvhui

调整 文章文本长度限制

... ... @@ -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
}
... ...
... ... @@ -2,11 +2,12 @@ package article
import (
"context"
"github.com/jinzhu/copier"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"strconv"
"unicode/utf8"
"github.com/jinzhu/copier"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"strings"
"github.com/samber/lo"
... ... @@ -199,7 +200,7 @@ func (l *SystemUpdateArticleLogic) validateTextLimit(req *types.SystemArticleUpd
num := utf8.RuneCountInString(req.Section[i].Content)
wordNum += num
}
if wordNum >= 1000 {
if wordNum > 1000 {
return xerr.NewErrMsg("最多只能输入1000字")
}
return nil
... ...