Merge branch 'ai/0.4.0/fix/tag' into test

This commit is contained in:
aichy126 2022-11-22 11:39:46 +08:00
commit e3e9ee0663
4 changed files with 56 additions and 39 deletions

View File

@ -78,6 +78,12 @@ backend:
tag: tag:
not_found: not_found:
other: "Tag not found." other: "Tag not found."
recommend_tag_not_found:
other: "Recommend Tag is not exist."
recommend_tag_enter:
other: "Please enter at least one required tag."
not_contain_synonym_tags:
other: "Should not contain synonym tags."
theme: theme:
not_found: not_found:
other: "Theme not found." other: "Theme not found."

View File

@ -50,4 +50,5 @@ const (
SiteInfoNotFound = "error.site_info.not_found" SiteInfoNotFound = "error.site_info.not_found"
UploadFileSourceUnsupported = "error.upload.source_unsupported" UploadFileSourceUnsupported = "error.upload.source_unsupported"
RecommendTagNotExist = "error.tag.recommend_tag_not_found" RecommendTagNotExist = "error.tag.recommend_tag_not_found"
RecommendTagEnter = "error.tag.recommend_tag_enter"
) )

View File

@ -227,6 +227,15 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
return return
} }
recommendExist, err := qs.tagCommon.ExistRecommend(ctx, req.Tags)
if err != nil {
return
}
if !recommendExist {
err = errors.BadRequest(reason.RecommendTagEnter).WithError(err).WithStack()
return
}
//CheckChangeTag //CheckChangeTag
oldTags, err := qs.tagCommon.GetObjectEntityTag(ctx, question.ID) oldTags, err := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
if err != nil { if err != nil {
@ -240,9 +249,10 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
if err != nil { if err != nil {
return return
} }
CheckTag, CheckTaglist := qs.CheckChangeTag(ctx, oldTags, Tags)
CheckTag, CheckTaglist := qs.CheckChangeReservedTag(ctx, oldTags, Tags)
if !CheckTag { if !CheckTag {
err = errors.BadRequest(reason.UnauthorizedError).WithMsg(fmt.Sprintf("tag [%s] cannot be modified", err = errors.BadRequest(reason.RequestFormatError).WithMsg(fmt.Sprintf("The reserved tag \"%s\" must be present.",
strings.Join(CheckTaglist, ","))) strings.Join(CheckTaglist, ",")))
return return
} }
@ -299,8 +309,8 @@ func (qs *QuestionService) ChangeTag(ctx context.Context, objectTagData *schema.
return qs.tagCommon.ObjectChangeTag(ctx, objectTagData) return qs.tagCommon.ObjectChangeTag(ctx, objectTagData)
} }
func (qs *QuestionService) CheckChangeTag(ctx context.Context, oldobjectTagData, objectTagData []*entity.Tag) (bool, []string) { func (qs *QuestionService) CheckChangeReservedTag(ctx context.Context, oldobjectTagData, objectTagData []*entity.Tag) (bool, []string) {
return qs.tagCommon.ObjectCheckChangeTag(ctx, oldobjectTagData, objectTagData) return qs.tagCommon.CheckChangeReservedTag(ctx, oldobjectTagData, objectTagData)
} }
func (qs *QuestionService) SearchUserList(ctx context.Context, userName, order string, page, pageSize int, loginUserID string) ([]*schema.UserQuestionInfo, int64, error) { func (qs *QuestionService) SearchUserList(ctx context.Context, userName, order string, page, pageSize int, loginUserID string) ([]*schema.UserQuestionInfo, int64, error) {

View File

@ -403,7 +403,7 @@ func (ts *TagCommonService) CheckTag(ctx context.Context, tags []string, userID
return nil return nil
} }
func (ts *TagCommonService) ObjectCheckChangeTag(ctx context.Context, oldobjectTagData, objectTagData []*entity.Tag) (bool, []string) { func (ts *TagCommonService) CheckChangeReservedTag(ctx context.Context, oldobjectTagData, objectTagData []*entity.Tag) (bool, []string) {
reservedTagsMap := make(map[string]bool) reservedTagsMap := make(map[string]bool)
needTagsMap := make([]string, 0) needTagsMap := make([]string, 0)
for _, tag := range objectTagData { for _, tag := range objectTagData {