mirror of https://gitee.com/answerdev/answer.git
update tag recommend show
This commit is contained in:
parent
f6095fd476
commit
177b99f475
|
@ -115,7 +115,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
||||||
userCommon := usercommon.NewUserCommon(userRepo)
|
userCommon := usercommon.NewUserCommon(userRepo)
|
||||||
answerRepo := answer.NewAnswerRepo(dataData, uniqueIDRepo, userRankRepo, activityRepo)
|
answerRepo := answer.NewAnswerRepo(dataData, uniqueIDRepo, userRankRepo, activityRepo)
|
||||||
questionRepo := question.NewQuestionRepo(dataData, uniqueIDRepo)
|
questionRepo := question.NewQuestionRepo(dataData, uniqueIDRepo)
|
||||||
tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo)
|
tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo, siteInfoCommonService)
|
||||||
objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagRepo)
|
objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagRepo)
|
||||||
voteRepo := activity_common.NewVoteRepo(dataData, activityRepo)
|
voteRepo := activity_common.NewVoteRepo(dataData, activityRepo)
|
||||||
commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo)
|
commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo)
|
||||||
|
|
|
@ -7,29 +7,44 @@ import (
|
||||||
"github.com/answerdev/answer/internal/base/pager"
|
"github.com/answerdev/answer/internal/base/pager"
|
||||||
"github.com/answerdev/answer/internal/base/reason"
|
"github.com/answerdev/answer/internal/base/reason"
|
||||||
"github.com/answerdev/answer/internal/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
|
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||||
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
||||||
"github.com/answerdev/answer/internal/service/unique"
|
"github.com/answerdev/answer/internal/service/unique"
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
|
"github.com/segmentfault/pacman/log"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
// tagRepo tag repository
|
// tagRepo tag repository
|
||||||
type tagRepo struct {
|
type tagRepo struct {
|
||||||
data *data.Data
|
data *data.Data
|
||||||
uniqueIDRepo unique.UniqueIDRepo
|
uniqueIDRepo unique.UniqueIDRepo
|
||||||
|
siteInfoService *siteinfo_common.SiteInfoCommonService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTagRepo new repository
|
// NewTagRepo new repository
|
||||||
func NewTagRepo(
|
func NewTagRepo(
|
||||||
data *data.Data,
|
data *data.Data,
|
||||||
uniqueIDRepo unique.UniqueIDRepo,
|
uniqueIDRepo unique.UniqueIDRepo,
|
||||||
|
siteInfoService *siteinfo_common.SiteInfoCommonService,
|
||||||
|
|
||||||
) tagcommon.TagRepo {
|
) tagcommon.TagRepo {
|
||||||
return &tagRepo{
|
return &tagRepo{
|
||||||
data: data,
|
data: data,
|
||||||
uniqueIDRepo: uniqueIDRepo,
|
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
|
// AddTagList add tag
|
||||||
func (tr *tagRepo) AddTagList(ctx context.Context, tagList []*entity.Tag) (err error) {
|
func (tr *tagRepo) AddTagList(ctx context.Context, tagList []*entity.Tag) (err error) {
|
||||||
for _, item := range tagList {
|
for _, item := range tagList {
|
||||||
|
@ -55,6 +70,11 @@ func (tr *tagRepo) GetTagListByIDs(ctx context.Context, ids []string) (tagList [
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
for _, tag := range tagList {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +87,11 @@ func (tr *tagRepo) GetTagBySlugName(ctx context.Context, slugName string) (tagIn
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
return nil, false, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
tagInfo.Recommend = false
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +117,11 @@ func (tr *tagRepo) GetTagListByName(ctx context.Context, name string, limit int,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
for _, tag := range tagList {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +137,11 @@ func (tr *tagRepo) GetRecommendTagList(ctx context.Context) (tagList []*entity.T
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
for _, tag := range tagList {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +157,11 @@ func (tr *tagRepo) GetReservedTagList(ctx context.Context) (tagList []*entity.Ta
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
for _, tag := range tagList {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +174,11 @@ func (tr *tagRepo) GetTagListByNames(ctx context.Context, names []string) (tagLi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
for _, tag := range tagList {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +253,9 @@ func (tr *tagRepo) GetTagByID(ctx context.Context, tagID string) (
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
return nil, false, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +267,11 @@ func (tr *tagRepo) GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
for _, tag := range tagList {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,5 +302,10 @@ func (tr *tagRepo) GetTagPage(ctx context.Context, page, pageSize int, tag *enti
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
|
if !tr.tagRecommendStatus(ctx) {
|
||||||
|
for _, tag := range tagList {
|
||||||
|
tag.Recommend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue