Quellcode durchsuchen

标签数量限制

lichangdong vor 23 Stunden
Ursprung
Commit
f7c6a2eef5
1 geänderte Dateien mit 4 neuen und 0 gelöschten Zeilen
  1. 4 0
      internal/logic/label/label_import_logic.go

+ 4 - 0
internal/logic/label/label_import_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"encoding/json"
 	"entgo.io/ent/dialect/sql"
+	"github.com/zeromicro/go-zero/core/errorx"
 	"strings"
 	"time"
 	"wechat-api/ent"
@@ -32,6 +33,9 @@ func (l *LabelImportLogic) LabelImport(req *types.LabelImportReq) (resp *types.L
 	organizationId := l.ctx.Value("organizationId").(uint64)
 	contentString := req.Content
 	contentList := splitContent(contentString)
+	if len(contentList) > 200 {
+		return nil, errorx.NewInvalidArgumentError("有效标签数量不能超过200个")
+	}
 	existingLabels, err := l.svcCtx.DB.Label.Query().
 		Where(
 			label.NameIn(contentList...),