Skip to content

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 tags attribute

aichy1263662182ff302
diff --git a/internal/repo/tag/tag_repo.go b/internal/repo/tag/tag_repo.go
index ad7e17b9..e6251f0f 100644
--- a/internal/repo/tag/tag_repo.go
+++ b/internal/repo/tag/tag_repo.go
@@ -179,6 +179,24 @@ func (tr *tagRepo) UpdateTagSynonym(ctx context.Context, tagSlugNameList []strin
return
}
+func (tr *tagRepo) UpdateTagsAttribute(ctx context.Context, tags []string, attribute string, value bool) (err error) {
+ bean := &entity.Tag{}
+ switch attribute {
+ case "recommend":
+ bean.Recommend = value
+ case "reserved":
+ bean.Reserved = value
+ default:
+ return
+ }
+ session := tr.data.DB.In("slug_name", tags).Cols(attribute).UseBool(attribute)
+ _, err = session.Update(bean)
+ if err != nil {
+ err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ }
+ return
+}
+
// GetTagByID get tag one
func (tr *tagRepo) GetTagByID(ctx context.Context, tagID string) (
tag *entity.Tag, exist bool, err error,
diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go
index d6a53595..b50fbcf0 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -28,6 +28,7 @@ type TagRepo interface {
GetTagPage(ctx context.Context, page, pageSize int, tag *entity.Tag, queryCond string) (tagList []*entity.Tag, total int64, err error)
GetRecommendTagList(ctx context.Context) (tagList []*entity.Tag, err error)
GetReservedTagList(ctx context.Context) (tagList []*entity.Tag, err error)
+ UpdateTagsAttribute(ctx context.Context, tags []string, attribute string, value bool) (err error)
}
type TagRelRepo interface {
@@ -75,6 +76,10 @@ func (ts *TagCommonService) SetSiteWriteRecommendTag(ctx context.Context, tags [
if err != nil {
return err
}
+ err = ts.SetTagsAttribute(ctx, tags, "recommend", true)
+ if err != nil {
+ return err
+ }
return nil
}
@@ -92,10 +97,34 @@ func (ts *TagCommonService) SetSiteWriteReservedTag(ctx context.Context, tags []
if err != nil {
return err
}
+ err = ts.SetTagsAttribute(ctx, tags, "reserved", true)
+ if err != nil {
+ return err
+ }
return nil
}
-//
+// SetTagsAttribute
+func (ts *TagCommonService) SetTagsAttribute(ctx context.Context, tags []string, attribute string, value bool) (err error) {
+ var tagslist []string
+ switch attribute {
+ case "recommend":
+ tagslist, err = ts.GetSiteWriteRecommendTag(ctx)
+ case "reserved":
+ tagslist, err = ts.GetSiteWriteReservedTag(ctx)
+ default:
+ return
+ }
+ err = ts.tagRepo.UpdateTagsAttribute(ctx, tagslist, attribute, false)
+ if err != nil {
+ return err
+ }
+ err = ts.tagRepo.UpdateTagsAttribute(ctx, tags, attribute, value)
+ if err != nil {
+ return err
+ }
+ return nil
+}
// GetTagListByName
func (ts *TagCommonService) GetTagListByName(ctx context.Context, tagName string) (tagInfo *entity.Tag, exist bool, err error) {