From 5e2666390696bab4a491e4ca227c7fa2c84dfb2e Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Wed, 16 Nov 2022 11:48:02 +0800 Subject: [PATCH] update search show tags --- i18n/en_US.yaml | 2 ++ internal/base/reason/reason.go | 1 + internal/repo/search_common/search_repo.go | 6 ++++-- internal/service/tag_common/tag_common.go | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index c89a01ce..03e94e26 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -76,6 +76,8 @@ backend: other: "Tag not found." recommend_tag_not_found: other: "Recommend Tag is not exist." + not_contain_synonym_tags: + other: "Should not contain synonym tags." theme: not_found: other: "Theme not found." diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.go index 200e20cb..25ff1d2f 100644 --- a/internal/base/reason/reason.go +++ b/internal/base/reason/reason.go @@ -33,6 +33,7 @@ const ( UserSuspended = "error.user.suspended" ObjectNotFound = "error.object.not_found" TagNotFound = "error.tag.not_found" + TagNotContainSynonym = "error.tag.not_contain_synonym_tags" RankFailToMeetTheCondition = "error.rank.fail_to_meet_the_condition" ThemeNotFound = "error.theme.not_found" LangNotFound = "error.lang.not_found" diff --git a/internal/repo/search_common/search_repo.go b/internal/repo/search_common/search_repo.go index b973df8a..9c486613 100644 --- a/internal/repo/search_common/search_repo.go +++ b/internal/repo/search_common/search_repo.go @@ -3,10 +3,11 @@ package search_common import ( "context" "fmt" - "github.com/answerdev/answer/pkg/htmltext" "strings" "time" + "github.com/answerdev/answer/pkg/htmltext" + "github.com/answerdev/answer/internal/base/data" "github.com/answerdev/answer/internal/base/reason" "github.com/answerdev/answer/internal/entity" @@ -390,11 +391,12 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte) // get tags err = sr.data.DB. - Select("`display_name`,`slug_name`,`main_tag_slug_name`"). + Select("`display_name`,`slug_name`,`main_tag_slug_name`,`recommend`,`reserved`"). Table("tag"). Join("INNER", "tag_rel", "tag.id = tag_rel.tag_id"). Where(builder.Eq{"tag_rel.object_id": r["question_id"]}). And(builder.Eq{"tag_rel.status": entity.TagRelStatusAvailable}). + UseBool("recommend", "reserved"). Find(&tagsEntity) if err != nil { diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go index dfdce839..fb28d744 100644 --- a/internal/service/tag_common/tag_common.go +++ b/internal/service/tag_common/tag_common.go @@ -244,6 +244,10 @@ func (ts *TagCommonService) UpdateTag(ctx context.Context, tags []string, userID tagInDbMapping := make(map[string]*entity.Tag) for _, tag := range tagListInDb { + if tag.MainTagID != 0 { + err = errors.BadRequest(reason.TagNotContainSynonym).WithMsg(fmt.Sprintf("tag name:%s", tag.SlugName)) + return err + } tagInDbMapping[tag.SlugName] = tag thisTagIDList = append(thisTagIDList, tag.ID) }