Skip to content

Commit

Permalink
修改GetFavoriteList,新增GetFavoriteRelations
Browse files Browse the repository at this point in the history
  • Loading branch information
Darley-Wey committed Feb 21, 2023
1 parent ca900ee commit 7b242c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ go get github.com/ClubWeGo/usermicro@latest

go get github.com/ClubWeGo/relationmicro@latest


go get github.com/ClubWeGo/favoritemicro@latest

# 说明
1. 当前注册用户时,前端并未提供个人参数配置的能力,也没有提供更新用户信息的能力,所以在core.register_server处写死了初始化的用户背景图像和头像。在配置本项目时,请将对应文件名换成minio中存储的文件名。
31 changes: 19 additions & 12 deletions kitex_server/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ func GetFavoriteList(ctx context.Context, uid int64) (favorites *interaction.Fav
return nil, err
}
videos := videosResp.VideoSet
videoIdList := make([]int64, 0)
authorIdList := make([]int64, 0)
for _, v := range videos {
videoIdList = append(videoIdList, v.Id)
authorIdList = append(authorIdList, v.AuthorId)
}

Expand All @@ -72,20 +74,18 @@ func GetFavoriteList(ctx context.Context, uid int64) (favorites *interaction.Fav
return nil, errno.RPCErr
}
authors := resp.UserSet
isFavorites := make(map[int64]bool)
//isFollows := make(map[int64]bool)
isFollowSet, err := GetIsFollowSetByUserIdSet(uid, authorIdList)
isFavoriteMap, err := GetFavoriteRelations(ctx, uid, videoIdList)
if err != nil {
return nil, err
}
for _, v := range videos {
isFavorites[v.Id], _ = GetFavoriteRelation(ctx, uid, v.Id)
//isFollows[v.AuthorId] = Get
isFollowMap, err := GetIsFollowMapByUserIdSet(uid, authorIdList)
if err != nil {
return nil, err
}
return &interaction.FavoriteListResp{
StatusCode: favoriteListRes.BaseResp.StatusCode,
StatusMsg: favoriteListRes.BaseResp.StatusMsg,
VideoList: pack.Videos(videos, authors, isFavorites, isFollowSet),
VideoList: pack.Videos(videos, authors, isFavoriteMap, isFollowMap),
}, nil
}

Expand All @@ -100,6 +100,18 @@ func GetFavoriteRelation(ctx context.Context, uid int64, vid int64) (bool, error
return res.IsFavorite, nil
}

func GetFavoriteRelations(ctx context.Context, uid int64, vids []int64) (isFavoriteMap map[int64]bool, err error) {
res, err := FavoriteClient.FavoriteRelationsMethod(ctx, &favorite.FavoriteRelationsReq{
UserId: uid,
VideoIdList: vids,
})
if err != nil {
return nil, errno.RPCErr
}
isFavoriteMap = res.IsFavoriteMap
return isFavoriteMap, nil
}

func CountVideoFavorite(ctx context.Context, vid int64) (cnt int64, err error) {
res, err := FavoriteClient.VideoFavoriteCountMethod(ctx, &favorite.VideoFavoriteCountReq{
VideoId: vid,
Expand All @@ -119,8 +131,3 @@ func CountUserFavorite(ctx context.Context, uid int64) (int64, int64, error) {
}
return res.FavoriteCount, res.FavoritedCount, nil
}

// TODO : 传入userId切片,批量查询user对应的favorite, total_favorited
func GetFavoriteCountByUserIdSet(idSet []int64) (favoriteSet, favoritedSet []int64, err error) {
return []int64{}, []int64{}, nil
}

0 comments on commit 7b242c1

Please sign in to comment.