update tag show

This commit is contained in:
aichy126 2022-11-16 15:28:23 +08:00
parent 5e26663906
commit 0863eec2a0
9 changed files with 102 additions and 1 deletions

View File

@ -4776,6 +4776,12 @@ const docTemplate = `{
"description": "if main tag slug name is not empty, this tag is synonymous with the main tag",
"type": "string"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug name",
"type": "string"
@ -5054,6 +5060,12 @@ const docTemplate = `{
"description": "question amount",
"type": "integer"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug_name",
"type": "string"
@ -5114,6 +5126,12 @@ const docTemplate = `{
"description": "question amount",
"type": "integer"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug name",
"type": "string"
@ -5139,6 +5157,12 @@ const docTemplate = `{
"description": "if main tag slug name is not empty, this tag is synonymous with the main tag",
"type": "string"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug name",
"type": "string"
@ -5953,6 +5977,9 @@ const docTemplate = `{
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"type": "string"
}

View File

@ -4764,6 +4764,12 @@
"description": "if main tag slug name is not empty, this tag is synonymous with the main tag",
"type": "string"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug name",
"type": "string"
@ -5042,6 +5048,12 @@
"description": "question amount",
"type": "integer"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug_name",
"type": "string"
@ -5102,6 +5114,12 @@
"description": "question amount",
"type": "integer"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug name",
"type": "string"
@ -5127,6 +5145,12 @@
"description": "if main tag slug name is not empty, this tag is synonymous with the main tag",
"type": "string"
},
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"description": "slug name",
"type": "string"
@ -5941,6 +5965,9 @@
"recommend": {
"type": "boolean"
},
"reserved": {
"type": "boolean"
},
"slug_name": {
"type": "string"
}

View File

@ -368,6 +368,10 @@ definitions:
description: if main tag slug name is not empty, this tag is synonymous with
the main tag
type: string
recommend:
type: boolean
reserved:
type: boolean
slug_name:
description: slug name
type: string
@ -570,6 +574,10 @@ definitions:
question_count:
description: question amount
type: integer
recommend:
type: boolean
reserved:
type: boolean
slug_name:
description: slug_name
type: string
@ -615,6 +623,10 @@ definitions:
question_count:
description: question amount
type: integer
recommend:
type: boolean
reserved:
type: boolean
slug_name:
description: slug name
type: string
@ -634,6 +646,10 @@ definitions:
description: if main tag slug name is not empty, this tag is synonymous with
the main tag
type: string
recommend:
type: boolean
reserved:
type: boolean
slug_name:
description: slug name
type: string
@ -1223,6 +1239,8 @@ definitions:
type: string
recommend:
type: boolean
reserved:
type: boolean
slug_name:
type: string
type: object

View File

@ -128,7 +128,7 @@ func (tr *tagRepo) GetReservedTagList(ctx context.Context) (tagList []*entity.Ta
// GetTagListByNames get tag list all like name
func (tr *tagRepo) GetTagListByNames(ctx context.Context, names []string) (tagList []*entity.Tag, err error) {
tagList = make([]*entity.Tag, 0)
session := tr.data.DB.In("slug_name", names)
session := tr.data.DB.In("slug_name", names).UseBool("recommend", "reserved")
// session.Where(builder.Eq{"status": entity.TagStatusAvailable})
err = session.OrderBy("recommend desc,reserved desc,id desc").Find(&tagList)
if err != nil {

View File

@ -61,6 +61,8 @@ type GetTagResp struct {
MemberActions []*PermissionMemberAction `json:"member_actions"`
// if main tag slug name is not empty, this tag is synonymous with the main tag
MainTagSlugName string `json:"main_tag_slug_name"`
Recommend bool `json:"recommend"`
Reserved bool `json:"reserved"`
}
func (tr *GetTagResp) GetExcerpt() {
@ -96,6 +98,8 @@ type GetTagPageResp struct {
CreatedAt int64 `json:"created_at"`
// updated time
UpdatedAt int64 `json:"updated_at"`
Recommend bool `json:"recommend"`
Reserved bool `json:"reserved"`
}
func (tr *GetTagPageResp) GetExcerpt() {
@ -190,6 +194,8 @@ type GetTagSynonymsResp struct {
DisplayName string `json:"display_name"`
// if main tag slug name is not empty, this tag is synonymous with the main tag
MainTagSlugName string `json:"main_tag_slug_name"`
Recommend bool `json:"recommend"`
Reserved bool `json:"reserved"`
}
// UpdateTagSynonymReq update tag request
@ -218,6 +224,8 @@ type GetFollowingTagsResp struct {
DisplayName string `json:"display_name"`
// if main tag slug name is not empty, this tag is synonymous with the main tag
MainTagSlugName string `json:"main_tag_slug_name"`
Recommend bool `json:"recommend"`
Reserved bool `json:"reserved"`
}
type SearchTagLikeResp struct {

View File

@ -113,6 +113,8 @@ func (rs *RevisionService) parseItem(ctx context.Context, item *schema.GetRevisi
ParsedText: tag.ParsedText,
FollowCount: tag.FollowCount,
QuestionCount: tag.QuestionCount,
Recommend: tag.Recommend,
Reserved: tag.Reserved,
}
tagInfo.GetExcerpt()
item.ContentParsed = tagInfo

View File

@ -82,6 +82,8 @@ func (ts *TagSearch) Search(ctx context.Context) (resp []schema.SearchResp, tota
ParsedText: tag.ParsedText,
QuestionCount: tag.QuestionCount,
IsFollower: followed,
Recommend: tag.Recommend,
Reserved: tag.Reserved,
}
ts.Extra.GetExcerpt()

View File

@ -157,6 +157,8 @@ func (ts *TagService) GetTagInfo(ctx context.Context, req *schema.GetTagInfoReq)
resp.ParsedText = tagInfo.ParsedText
resp.FollowCount = tagInfo.FollowCount
resp.QuestionCount = tagInfo.QuestionCount
resp.Recommend = tagInfo.Recommend
resp.Reserved = tagInfo.Reserved
resp.IsFollower = ts.checkTagIsFollow(ctx, req.UserID, tagInfo.ID)
resp.MemberActions = permission.GetTagPermission(req.UserID, req.UserID)
resp.GetExcerpt()
@ -183,6 +185,8 @@ func (ts *TagService) GetFollowingTags(ctx context.Context, userID string) (
TagID: t.ID,
SlugName: t.SlugName,
DisplayName: t.DisplayName,
Recommend: t.Recommend,
Reserved: t.Reserved,
}
if t.MainTagID > 0 {
mainTag, exist, err := ts.tagRepo.GetTagByID(ctx, converter.IntToString(t.MainTagID))
@ -239,6 +243,8 @@ func (ts *TagService) GetTagSynonyms(ctx context.Context, req *schema.GetTagSyno
SlugName: t.SlugName,
DisplayName: t.DisplayName,
MainTagSlugName: mainTagSlugName,
Recommend: t.Recommend,
Reserved: t.Reserved,
})
}
return
@ -364,6 +370,8 @@ func (ts *TagService) GetTagWithPage(ctx context.Context, req *schema.GetTagWith
IsFollower: ts.checkTagIsFollow(ctx, req.UserID, tag.ID),
CreatedAt: tag.CreatedAt.Unix(),
UpdatedAt: tag.UpdatedAt.Unix(),
Recommend: tag.Recommend,
Reserved: tag.Reserved,
})
}
return pager.NewPageModel(total, resp), nil

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"
"github.com/answerdev/answer/internal/base/reason"
@ -221,6 +222,14 @@ func (ts *TagCommonService) BatchGetObjectTag(ctx context.Context, objectIds []s
objectIDTagMap[item.ObjectID] = append(objectIDTagMap[item.ObjectID], t)
}
}
for _, taglist := range objectIDTagMap {
sort.SliceStable(taglist, func(i, j int) bool {
return taglist[i].Reserved
})
sort.SliceStable(taglist, func(i, j int) bool {
return taglist[i].Recommend
})
}
return objectIDTagMap, nil
}