This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.6/template
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/feat/1.3.6/template by this
push:
new 6c553f52 feat(admin): update recommend_tags and reserved_tags filed in
site write req
6c553f52 is described below
commit 6c553f52f849082c8799930d37718772a595e7f8
Author: LinkinStars <[email protected]>
AuthorDate: Thu Jul 11 17:53:59 2024 +0800
feat(admin): update recommend_tags and reserved_tags filed in site write req
---
internal/migrations/v18.go | 9 ++++-
internal/schema/siteinfo_schema.go | 16 ++++++---
internal/service/siteinfo/siteinfo_service.go | 9 ++++-
internal/service/tag_common/tag_common.go | 49 ++++++++++++++++-----------
4 files changed, 57 insertions(+), 26 deletions(-)
diff --git a/internal/migrations/v18.go b/internal/migrations/v18.go
index 3ad8325f..26dc6da5 100644
--- a/internal/migrations/v18.go
+++ b/internal/migrations/v18.go
@@ -57,7 +57,14 @@ func addPasswordLoginControl(ctx context.Context, x
*xorm.Engine) error {
return fmt.Errorf("get config failed: %w", err)
}
if exist {
- content := &schema.SiteWriteReq{}
+ type OldSiteWriteReq struct {
+ RestrictAnswer bool `validate:"omitempty"
form:"restrict_answer" json:"restrict_answer"`
+ RequiredTag bool `validate:"omitempty"
form:"required_tag" json:"required_tag"`
+ RecommendTags []string `validate:"omitempty"
form:"recommend_tags" json:"recommend_tags"`
+ ReservedTags []string `validate:"omitempty"
form:"reserved_tags" json:"reserved_tags"`
+ UserID string `json:"-"`
+ }
+ content := &OldSiteWriteReq{}
_ = json.Unmarshal([]byte(writeSiteInfo.Content), content)
content.RestrictAnswer = true
data, _ := json.Marshal(content)
diff --git a/internal/schema/siteinfo_schema.go
b/internal/schema/siteinfo_schema.go
index 875407b2..99266308 100644
--- a/internal/schema/siteinfo_schema.go
+++ b/internal/schema/siteinfo_schema.go
@@ -72,11 +72,17 @@ type SiteBrandingReq struct {
// SiteWriteReq site write request
type SiteWriteReq struct {
- RestrictAnswer bool `validate:"omitempty" form:"restrict_answer"
json:"restrict_answer"`
- RequiredTag bool `validate:"omitempty" form:"required_tag"
json:"required_tag"`
- RecommendTags []string `validate:"omitempty" form:"recommend_tags"
json:"recommend_tags"`
- ReservedTags []string `validate:"omitempty" form:"reserved_tags"
json:"reserved_tags"`
- UserID string `json:"-"`
+ RestrictAnswer bool `validate:"omitempty"
json:"restrict_answer"`
+ RequiredTag bool `validate:"omitempty"
json:"required_tag"`
+ RecommendTags []*SiteWriteTag `validate:"omitempty,dive"
json:"recommend_tags"`
+ ReservedTags []*SiteWriteTag `validate:"omitempty,dive"
json:"reserved_tags"`
+ UserID string `json:"-"`
+}
+
+// SiteWriteTag site write response tag
+type SiteWriteTag struct {
+ SlugName string `validate:"required" json:"slug_name"`
+ DisplayName string `json:"display_name"`
}
// SiteLegalReq site branding request
diff --git a/internal/service/siteinfo/siteinfo_service.go
b/internal/service/siteinfo/siteinfo_service.go
index f82a7c7f..c7f1f9ce 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -180,7 +180,14 @@ func (s *SiteInfoService) SaveSiteBranding(ctx
context.Context, req *schema.Site
// SaveSiteWrite save site configuration about write
func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req
*schema.SiteWriteReq) (resp interface{}, err error) {
- errData, err := s.tagCommonService.SetSiteWriteTag(ctx,
req.RecommendTags, req.ReservedTags, req.UserID)
+ recommendTags, reservedTags := make([]string, 0), make([]string, 0)
+ for _, tag := range req.RecommendTags {
+ recommendTags = append(recommendTags, tag.SlugName)
+ }
+ for _, tag := range req.ReservedTags {
+ reservedTags = append(reservedTags, tag.SlugName)
+ }
+ errData, err := s.tagCommonService.SetSiteWriteTag(ctx, recommendTags,
reservedTags, req.UserID)
if err != nil {
return errData, err
}
diff --git a/internal/service/tag_common/tag_common.go
b/internal/service/tag_common/tag_common.go
index 1dfe4f7f..e6e7a076 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -158,14 +158,32 @@ func (ts *TagCommonService) SearchTagLike(ctx
context.Context, req *schema.Searc
return resp, nil
}
-func (ts *TagCommonService) GetSiteWriteRecommendTag(ctx context.Context)
(tags []string, err error) {
- tags = make([]string, 0)
+func (ts *TagCommonService) GetSiteWriteRecommendTag(ctx context.Context)
(tags []*schema.SiteWriteTag, err error) {
+ tags = make([]*schema.SiteWriteTag, 0)
list, err := ts.tagCommonRepo.GetRecommendTagList(ctx)
if err != nil {
return tags, err
}
for _, item := range list {
- tags = append(tags, item.SlugName)
+ tags = append(tags, &schema.SiteWriteTag{
+ SlugName: item.SlugName,
+ DisplayName: item.DisplayName,
+ })
+ }
+ return tags, nil
+}
+
+func (ts *TagCommonService) GetSiteWriteReservedTag(ctx context.Context) (tags
[]*schema.SiteWriteTag, err error) {
+ tags = make([]*schema.SiteWriteTag, 0)
+ list, err := ts.tagCommonRepo.GetReservedTagList(ctx)
+ if err != nil {
+ return tags, err
+ }
+ for _, item := range list {
+ tags = append(tags, &schema.SiteWriteTag{
+ SlugName: item.SlugName,
+ DisplayName: item.DisplayName,
+ })
}
return tags, nil
}
@@ -203,33 +221,26 @@ func (ts *TagCommonService) SetSiteWriteTag(ctx
context.Context, recommendTags,
return nil, nil
}
-func (ts *TagCommonService) GetSiteWriteReservedTag(ctx context.Context) (tags
[]string, err error) {
- tags = make([]string, 0)
- list, err := ts.tagCommonRepo.GetReservedTagList(ctx)
- if err != nil {
- return tags, err
- }
- for _, item := range list {
- tags = append(tags, item.SlugName)
- }
- return tags, nil
-}
-
// SetTagsAttribute
func (ts *TagCommonService) SetTagsAttribute(ctx context.Context, tags
[]string, attribute string) (err error) {
- var tagslist []string
+ var oldTags []*entity.Tag
switch attribute {
case "recommend":
- tagslist, err = ts.GetSiteWriteRecommendTag(ctx)
+ oldTags, err = ts.tagCommonRepo.GetRecommendTagList(ctx)
case "reserved":
- tagslist, err = ts.GetSiteWriteReservedTag(ctx)
+ oldTags, err = ts.tagCommonRepo.GetReservedTagList(ctx)
default:
return
}
if err != nil {
return err
}
- err = ts.tagCommonRepo.UpdateTagsAttribute(ctx, tagslist, attribute,
false)
+ oldTagSlugNameList := make([]string, 0)
+ for _, tag := range oldTags {
+ oldTagSlugNameList = append(oldTagSlugNameList, tag.SlugName)
+ }
+
+ err = ts.tagCommonRepo.UpdateTagsAttribute(ctx, oldTagSlugNameList,
attribute, false)
if err != nil {
return err
}