mirror of https://gitee.com/answerdev/answer.git
Merge branch 'ai/0.4.0/tag' into test
This commit is contained in:
commit
045257cd07
|
@ -116,7 +116,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)
|
||||
|
|
|
@ -7,9 +7,11 @@ 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"
|
||||
)
|
||||
|
||||
|
@ -17,19 +19,32 @@ import (
|
|||
type tagRepo struct {
|
||||
data *data.Data
|
||||
uniqueIDRepo unique.UniqueIDRepo
|
||||
siteInfoService *siteinfo_common.SiteInfoCommonService
|
||||
}
|
||||
|
||||
// NewTagRepo new repository
|
||||
func NewTagRepo(
|
||||
data *data.Data,
|
||||
uniqueIDRepo unique.UniqueIDRepo,
|
||||
siteInfoService *siteinfo_common.SiteInfoCommonService,
|
||||
|
||||
) tagcommon.TagRepo {
|
||||
return &tagRepo{
|
||||
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
|
||||
func (tr *tagRepo) AddTagList(ctx context.Context, tagList []*entity.Tag) (err error) {
|
||||
for _, item := range tagList {
|
||||
|
@ -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) (tagIn
|
|||
if 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.T
|
|||
if 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.Ta
|
|||
if 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) (tagLi
|
|||
if 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 *enti
|
|||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
}
|
||||
if !tr.tagRecommendStatus(ctx) {
|
||||
for _, tag := range tagList {
|
||||
tag.Recommend = false
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue