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.
update tag recommend show
aichy126177b99f47544
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.goindex dbd2a848..f035cbe4 100644--- a/cmd/answer/wire_gen.go+++ b/cmd/answer/wire_gen.go@@ -115,7 +115,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,userCommon := usercommon.NewUserCommon(userRepo)answerRepo := answer.NewAnswerRepo(dataData, uniqueIDRepo, userRankRepo, activityRepo)questionRepo := question.NewQuestionRepo(dataData, uniqueIDRepo)- tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo)+ tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo, siteInfoCommonService)objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagRepo)voteRepo := activity_common.NewVoteRepo(dataData, activityRepo)commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo)diff --git a/internal/repo/tag/tag_repo.go b/internal/repo/tag/tag_repo.goindex 76ab6cbf..02ae9c39 100644--- a/internal/repo/tag/tag_repo.go+++ b/internal/repo/tag/tag_repo.go@@ -7,27 +7,42 @@ import ("github.com/answerdev/answer/internal/base/pager""github.com/answerdev/answer/internal/base/reason""github.com/answerdev/answer/internal/entity"+ "github.com/answerdev/answer/internal/service/siteinfo_common"tagcommon "github.com/answerdev/answer/internal/service/tag_common""github.com/answerdev/answer/internal/service/unique""github.com/segmentfault/pacman/errors"+ "github.com/segmentfault/pacman/log""xorm.io/builder")// tagRepo tag repositorytype tagRepo struct {- data *data.Data- uniqueIDRepo unique.UniqueIDRepo+ data *data.Data+ uniqueIDRepo unique.UniqueIDRepo+ siteInfoService *siteinfo_common.SiteInfoCommonService}// NewTagRepo new repositoryfunc NewTagRepo(data *data.Data,uniqueIDRepo unique.UniqueIDRepo,+ siteInfoService *siteinfo_common.SiteInfoCommonService,+) tagcommon.TagRepo {return &tagRepo{- data: data,- uniqueIDRepo: uniqueIDRepo,+ data: data,+ uniqueIDRepo: uniqueIDRepo,+ siteInfoService: siteInfoService,+ }+}++func (tr *tagRepo) tagRecommendStatus(ctx context.Context) bool {+ tagconfig, err := tr.siteInfoService.GetSiteWrite(ctx)+ if err != nil {+ log.Error("siteInfoService.GetSiteWrite error", err)+ return false}+ return tagconfig.RequiredTag}// AddTagList add tag@@ -55,6 +70,11 @@ func (tr *tagRepo) GetTagListByIDs(ctx context.Context, ids []string) (tagList [if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ for _, tag := range tagList {+ tag.Recommend = false+ }+ }return}@@ -67,6 +87,11 @@ func (tr *tagRepo) GetTagBySlugName(ctx context.Context, slugName string) (tagInif err != nil {return nil, false, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}++ if !tr.tagRecommendStatus(ctx) {+ tagInfo.Recommend = false+ }+return}@@ -92,6 +117,11 @@ func (tr *tagRepo) GetTagListByName(ctx context.Context, name string, limit int,if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ for _, tag := range tagList {+ tag.Recommend = false+ }+ }return}@@ -107,6 +137,11 @@ func (tr *tagRepo) GetRecommendTagList(ctx context.Context) (tagList []*entity.Tif err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ for _, tag := range tagList {+ tag.Recommend = false+ }+ }return}@@ -122,6 +157,11 @@ func (tr *tagRepo) GetReservedTagList(ctx context.Context) (tagList []*entity.Taif err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ for _, tag := range tagList {+ tag.Recommend = false+ }+ }return}@@ -134,6 +174,11 @@ func (tr *tagRepo) GetTagListByNames(ctx context.Context, names []string) (tagLiif err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ for _, tag := range tagList {+ tag.Recommend = false+ }+ }return}@@ -208,6 +253,9 @@ func (tr *tagRepo) GetTagByID(ctx context.Context, tagID string) (if err != nil {return nil, false, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ tag.Recommend = false+ }return}@@ -219,6 +267,11 @@ func (tr *tagRepo) GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ for _, tag := range tagList {+ tag.Recommend = false+ }+ }return}@@ -249,5 +302,10 @@ func (tr *tagRepo) GetTagPage(ctx context.Context, page, pageSize int, tag *entiif err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}+ if !tr.tagRecommendStatus(ctx) {+ for _, tag := range tagList {+ tag.Recommend = false+ }+ }return}