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.
feat(tag): update tags search API
LinkinStarsb7ebe3083b71
diff --git a/internal/controller/tag_controller.go b/internal/controller/tag_controller.goindex 11b1fcde..5f5cf5fb 100644--- a/internal/controller/tag_controller.go+++ b/internal/controller/tag_controller.go@@ -20,8 +20,6 @@package controllerimport (- "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.goindex 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 nametype 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.goindex 64d17183..01864163 100644--- a/internal/service/tag/tag_service.go+++ b/internal/service/tag/tag_service.go@@ -22,6 +22,7 @@ package tagimport ("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 tagsdiff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.goindex 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.Searctag.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.SlugNameitem.DisplayName = tag.DisplayNameitem.Recommend = tag.Recommend