@@ -24,7 +24,7 @@ type TagCommonRepo interface {
2424 AddTagList (ctx context.Context , tagList []* entity.Tag ) (err error )
2525 GetTagListByIDs (ctx context.Context , ids []string ) (tagList []* entity.Tag , err error )
2626 GetTagBySlugName (ctx context.Context , slugName string ) (tagInfo * entity.Tag , exist bool , err error )
27- GetTagListByName (ctx context.Context , name string , hasReserved bool ) (tagList []* entity.Tag , err error )
27+ GetTagListByName (ctx context.Context , name string , recommend , reserved bool ) (tagList []* entity.Tag , err error )
2828 GetTagListByNames (ctx context.Context , names []string ) (tagList []* entity.Tag , err error )
2929 GetTagByID (ctx context.Context , tagID string , includeDeleted bool ) (tag * entity.Tag , exist bool , err error )
3030 GetTagPage (ctx context.Context , page , pageSize int , tag * entity.Tag , queryCond string ) (tagList []* entity.Tag , total int64 , err error )
@@ -86,7 +86,7 @@ func NewTagCommonService(
8686
8787// SearchTagLike get tag list all
8888func (ts * TagCommonService ) SearchTagLike (ctx context.Context , req * schema.SearchTagLikeReq ) (resp []schema.SearchTagLikeResp , err error ) {
89- tags , err := ts .tagCommonRepo .GetTagListByName (ctx , req .Tag , req .IsAdmin )
89+ tags , err := ts .tagCommonRepo .GetTagListByName (ctx , req .Tag , len ( req .Tag ) == 0 , false )
9090 if err != nil {
9191 return
9292 }
@@ -97,35 +97,39 @@ func (ts *TagCommonService) SearchTagLike(ctx context.Context, req *schema.Searc
9797 mainTagId = append (mainTagId , converter .IntToString (tag .MainTagID ))
9898 }
9999 }
100- mainTagList , err := ts .tagCommonRepo .GetTagListByIDs (ctx , mainTagId )
101- if err != nil {
102- return
103- }
104100 mainTagMap := make (map [string ]* entity.Tag )
105- for _ , tag := range mainTagList {
106- mainTagMap [tag .ID ] = tag
101+ if len (mainTagId ) > 0 {
102+ mainTagList , err := ts .tagCommonRepo .GetTagListByIDs (ctx , mainTagId )
103+ if err != nil {
104+ return nil , err
105+ }
106+ for _ , tag := range mainTagList {
107+ mainTagMap [tag .ID ] = tag
108+ }
107109 }
108110 for _ , tag := range tags {
109- if tag .MainTagID != 0 {
110- _ , ok := mainTagMap [converter .IntToString (tag .MainTagID )]
111- if ok {
112- tag .SlugName = mainTagMap [converter .IntToString (tag .MainTagID )].SlugName
113- tag .DisplayName = mainTagMap [converter .IntToString (tag .MainTagID )].DisplayName
114- tag .Reserved = mainTagMap [converter .IntToString (tag .MainTagID )].Reserved
115- tag .Recommend = mainTagMap [converter .IntToString (tag .MainTagID )].Recommend
116- }
111+ if tag .MainTagID == 0 {
112+ continue
113+ }
114+ mainTagID := converter .IntToString (tag .MainTagID )
115+ if _ , ok := mainTagMap [mainTagID ]; ok {
116+ tag .SlugName = mainTagMap [mainTagID ].SlugName
117+ tag .DisplayName = mainTagMap [mainTagID ].DisplayName
118+ tag .Reserved = mainTagMap [mainTagID ].Reserved
119+ tag .Recommend = mainTagMap [mainTagID ].Recommend
117120 }
118121 }
119- RepetitiveTag := make (map [string ]bool )
122+ resp = make ([]schema.SearchTagLikeResp , 0 )
123+ repetitiveTag := make (map [string ]bool )
120124 for _ , tag := range tags {
121- if _ , ok := RepetitiveTag [tag .SlugName ]; ! ok {
125+ if _ , ok := repetitiveTag [tag .SlugName ]; ! ok {
122126 item := schema.SearchTagLikeResp {}
123127 item .SlugName = tag .SlugName
124128 item .DisplayName = tag .DisplayName
125129 item .Recommend = tag .Recommend
126130 item .Reserved = tag .Reserved
127131 resp = append (resp , item )
128- RepetitiveTag [tag .SlugName ] = true
132+ repetitiveTag [tag .SlugName ] = true
129133 }
130134 }
131135 return resp , nil
0 commit comments