You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/07/12 08:40:12 UTC
(incubator-answer) branch feat/1.3.6/template updated (6c553f52 -> c4318f1d)
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a change to branch feat/1.3.6/template
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
from 6c553f52 feat(admin): update recommend_tags and reserved_tags filed in site write req
new b7ebe308 feat(tag): update tags search API
new c4318f1d feat(tag): recommend tags can't contain reserved tag
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
internal/controller/tag_controller.go | 15 ++++++---------
internal/schema/tag_schema.go | 9 +++++----
internal/service/siteinfo/siteinfo_service.go | 20 ++++++++++++++++----
internal/service/tag/tag_service.go | 25 ++++++++++++++++---------
internal/service/tag_common/tag_common.go | 6 +++---
5 files changed, 46 insertions(+), 29 deletions(-)
(incubator-answer) 01/02: feat(tag): update tags search API
Posted by li...@apache.org.
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
commit b7ebe3083b717f0556ab5f27c79502b5380be1c3
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Fri Jul 12 10:59:28 2024 +0800
feat(tag): update tags search API
---
internal/controller/tag_controller.go | 15 ++++++---------
internal/schema/tag_schema.go | 9 +++++----
internal/service/tag/tag_service.go | 25 ++++++++++++++++---------
internal/service/tag_common/tag_common.go | 6 +++---
4 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/internal/controller/tag_controller.go b/internal/controller/tag_controller.go
index 11b1fcde..5f5cf5fb 100644
--- a/internal/controller/tag_controller.go
+++ b/internal/controller/tag_controller.go
@@ -20,8 +20,6 @@
package controller
import (
- "strings"
-
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/middleware"
"github.com/apache/incubator-answer/internal/base/reason"
@@ -57,7 +55,7 @@ func NewTagController(
// @Produce json
// @Security ApiKeyAuth
// @Param tag query string false "tag"
-// @Success 200 {object} handler.RespBody{data=[]schema.GetTagResp}
+// @Success 200 {object} handler.RespBody{data=[]schema.GetTagBasicResp}
// @Router /answer/api/v1/question/tags [get]
func (tc *TagController) SearchTagLike(ctx *gin.Context) {
req := &schema.SearchTagLikeReq{}
@@ -68,22 +66,21 @@ func (tc *TagController) SearchTagLike(ctx *gin.Context) {
handler.HandleResponse(ctx, err, resp)
}
-// GetTagsBySlugName
+// GetTagsBySlugName get tags list
// @Summary get tags list
-// @Description get tags list
+// @Description get tags list by slug name
// @Tags Tag
// @Produce json
// @Param tags query []string false "string collection" collectionFormat(csv)
-// @Success 200 {object} handler.RespBody{}
+// @Success 200 {object} handler.RespBody{data=[]schema.GetTagBasicResp}
// @Router /answer/api/v1/tags [get]
func (tc *TagController) GetTagsBySlugName(ctx *gin.Context) {
req := &schema.SearchTagsBySlugName{}
if handler.BindAndCheck(ctx, req) {
return
}
- req.TagList = strings.Split(req.Tags, ",")
- // req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
- resp, err := tc.tagService.GetTagsBySlugName(ctx, req.TagList)
+
+ resp, err := tc.tagService.GetTagsBySlugName(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
diff --git a/internal/schema/tag_schema.go b/internal/schema/tag_schema.go
index d283ba73..888c224b 100644
--- a/internal/schema/tag_schema.go
+++ b/internal/schema/tag_schema.go
@@ -33,10 +33,10 @@ type SearchTagLikeReq struct {
IsAdmin bool `json:"-"`
}
+// SearchTagsBySlugName search tags by slug name
type SearchTagsBySlugName struct {
- Tags string `json:"tags" form:"tags"`
- TagList []string `json:"-"`
- IsAdmin bool `json:"-"`
+ // slug name list split by ','
+ Tags string `form:"tags"`
}
// GetTagInfoReq get tag info request
@@ -298,7 +298,8 @@ type GetFollowingTagsResp struct {
Reserved bool `json:"reserved"`
}
-type SearchTagLikeResp struct {
+// GetTagBasicResp get tag basic response
+type GetTagBasicResp struct {
SlugName string `json:"slug_name"`
DisplayName string `json:"display_name"`
Recommend bool `json:"recommend"`
diff --git a/internal/service/tag/tag_service.go b/internal/service/tag/tag_service.go
index 64d17183..01864163 100644
--- a/internal/service/tag/tag_service.go
+++ b/internal/service/tag/tag_service.go
@@ -22,6 +22,7 @@ package tag
import (
"context"
"encoding/json"
+ "strings"
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/service/activity_queue"
@@ -190,18 +191,24 @@ func (ts *TagService) GetTagInfo(ctx context.Context, req *schema.GetTagInfoReq)
return resp, nil
}
-func (ts *TagService) GetTagsBySlugName(ctx context.Context, tagNames []string) ([]*schema.TagItem, error) {
- tagList := make([]*schema.TagItem, 0)
- tagListInDB, err := ts.tagCommonService.GetTagListByNames(ctx, tagNames)
+// GetTagsBySlugName get tags by slug name
+func (ts *TagService) GetTagsBySlugName(ctx context.Context, req *schema.SearchTagsBySlugName) (
+ resp []*schema.GetTagBasicResp, err error) {
+ resp = make([]*schema.GetTagBasicResp, 0)
+ tagSlugNames := strings.Split(req.Tags, ",")
+ if len(tagSlugNames) == 0 {
+ return resp, nil
+ }
+ tagList, err := ts.tagCommonService.GetTagListByNames(ctx, tagSlugNames)
if err != nil {
- return tagList, err
+ return resp, err
}
- for _, tag := range tagListInDB {
- tagItem := &schema.TagItem{}
- copier.Copy(tagItem, tag)
- tagList = append(tagList, tagItem)
+ for _, tag := range tagList {
+ tagItem := &schema.GetTagBasicResp{}
+ _ = copier.Copy(tagItem, tag)
+ resp = append(resp, tagItem)
}
- return tagList, nil
+ return resp, nil
}
// GetFollowingTags get following tags
diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go
index e6e7a076..239b3c3f 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -108,7 +108,7 @@ func NewTagCommonService(
}
// SearchTagLike get tag list all
-func (ts *TagCommonService) SearchTagLike(ctx context.Context, req *schema.SearchTagLikeReq) (resp []schema.SearchTagLikeResp, err error) {
+func (ts *TagCommonService) SearchTagLike(ctx context.Context, req *schema.SearchTagLikeReq) (resp []schema.GetTagBasicResp, err error) {
tags, err := ts.tagCommonRepo.GetTagListByName(ctx, req.Tag, len(req.Tag) == 0, false)
if err != nil {
return
@@ -142,11 +142,11 @@ func (ts *TagCommonService) SearchTagLike(ctx context.Context, req *schema.Searc
tag.Recommend = mainTagMap[mainTagID].Recommend
}
}
- resp = make([]schema.SearchTagLikeResp, 0)
+ resp = make([]schema.GetTagBasicResp, 0)
repetitiveTag := make(map[string]bool)
for _, tag := range tags {
if _, ok := repetitiveTag[tag.SlugName]; !ok {
- item := schema.SearchTagLikeResp{}
+ item := schema.GetTagBasicResp{}
item.SlugName = tag.SlugName
item.DisplayName = tag.DisplayName
item.Recommend = tag.Recommend
(incubator-answer) 02/02: feat(tag): recommend tags can't contain reserved tag
Posted by li...@apache.org.
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
commit c4318f1d18f96d73b9e2b90458f8ad5c2ece62e0
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Fri Jul 12 16:40:02 2024 +0800
feat(tag): recommend tags can't contain reserved tag
---
internal/service/siteinfo/siteinfo_service.go | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go
index c7f1f9ce..ce71900d 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -181,11 +181,23 @@ 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) {
recommendTags, reservedTags := make([]string, 0), make([]string, 0)
- for _, tag := range req.RecommendTags {
- recommendTags = append(recommendTags, tag.SlugName)
- }
+ recommendTagMapping, reservedTagMapping := make(map[string]bool), make(map[string]bool)
for _, tag := range req.ReservedTags {
- reservedTags = append(reservedTags, tag.SlugName)
+ if !recommendTagMapping[tag.SlugName] {
+ reservedTagMapping[tag.SlugName] = true
+ reservedTags = append(reservedTags, tag.SlugName)
+ }
+ }
+
+ // recommend tags can't contain reserved tag
+ for _, tag := range req.RecommendTags {
+ if reservedTagMapping[tag.SlugName] {
+ continue
+ }
+ if !recommendTagMapping[tag.SlugName] {
+ recommendTagMapping[tag.SlugName] = true
+ recommendTags = append(recommendTags, tag.SlugName)
+ }
}
errData, err := s.tagCommonService.SetSiteWriteTag(ctx, recommendTags, reservedTags, req.UserID)
if err != nil {