A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
add GetTagSynonymCount
aichy126c9b697318ff2
diff --git a/internal/repo/tag/tag_repo.go b/internal/repo/tag/tag_repo.goindex 0c1169e0..02604cb7 100644--- a/internal/repo/tag/tag_repo.go+++ b/internal/repo/tag/tag_repo.go@@ -8,6 +8,7 @@ import ("github.com/answerdev/answer/internal/entity""github.com/answerdev/answer/internal/service/tag_common""github.com/answerdev/answer/internal/service/unique"+ "github.com/answerdev/answer/pkg/converter""github.com/segmentfault/pacman/errors""xorm.io/builder")@@ -61,6 +62,14 @@ func (tr *tagRepo) UpdateTagSynonym(ctx context.Context, tagSlugNameList []strinreturn}+func (tr *tagRepo) GetTagSynonymCount(ctx context.Context, tagID string) (count int64, err error) {+ count, err = tr.data.DB.Count(&entity.Tag{MainTagID: converter.StringToInt64(tagID), Status: entity.TagStatusAvailable})+ if err != nil {+ err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ }+ return+}+// GetTagList get tag list allfunc (tr *tagRepo) GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error) {tagList = make([]*entity.Tag, 0)diff --git a/internal/service/tag/tag_service.go b/internal/service/tag/tag_service.goindex d4c4d256..2497b2c7 100644--- a/internal/service/tag/tag_service.go+++ b/internal/service/tag/tag_service.go@@ -50,14 +50,24 @@ func NewTagService(// RemoveTag delete tagfunc (ts *TagService) RemoveTag(ctx context.Context, req *schema.RemoveTagReq) (err error) {+ //If the tag has associated problems, it cannot be deletedtagCount, err := ts.tagCommonService.CountTagRelByTagID(ctx, req.TagID)if err != nil {return err}- //If the tag has associated problems, it cannot be deletedif tagCount > 0 {return errors.BadRequest(reason.TagIsUsedCannotDelete)}++ //If the tag has associated problems, it cannot be deleted+ tagSynonymCount, err := ts.tagRepo.GetTagSynonymCount(ctx, req.TagID)+ if err != nil {+ return err+ }+ if tagSynonymCount > 0 {+ return errors.BadRequest(reason.TagIsUsedCannotDelete)+ }+// tagRelRepoerr = ts.tagRepo.RemoveTag(ctx, req.TagID)if err != nil {diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.goindex 824a46ee..da7ec466 100644--- a/internal/service/tag_common/tag_common.go+++ b/internal/service/tag_common/tag_common.go@@ -38,6 +38,7 @@ type TagRepo interface {RemoveTag(ctx context.Context, tagID string) (err error)UpdateTag(ctx context.Context, tag *entity.Tag) (err error)UpdateTagSynonym(ctx context.Context, tagSlugNameList []string, mainTagID int64, mainTagSlugName string) (err error)+ GetTagSynonymCount(ctx context.Context, tagID string) (count int64, err error)GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error)}