-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ClubWeGo/master
merge daley's changes
- Loading branch information
Showing
3 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package pack | ||
|
||
import ( | ||
"github.com/ClubWeGo/douyin/biz/model/core" | ||
"github.com/ClubWeGo/usermicro/kitex_gen/usermicro" | ||
"strconv" | ||
) | ||
|
||
// User 将 usermicro.UserInfo 转换为 core.User,针对每个用户,需要预先把对作者的关注状态传入 | ||
func User(user *usermicro.UserInfo, isFollow bool) *core.User { | ||
return &core.User{ | ||
ID: user.Id, | ||
Name: user.Name, | ||
FollowCount: user.FollowCount, | ||
FollowerCount: user.FollowerCount, | ||
IsFollow: isFollow, | ||
Avatar: user.Avatar, | ||
BackgroundImage: user.BackgroundImage, | ||
Signature: user.Signature, | ||
TotalFavourited: strconv.FormatInt(user.TotalFavorited, 10), | ||
WorkCount: user.WorkCount, | ||
FavoriteCount: user.FavoriteCount, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package pack | ||
|
||
import ( | ||
"github.com/ClubWeGo/douyin/biz/model/core" | ||
"github.com/ClubWeGo/usermicro/kitex_gen/usermicro" | ||
"github.com/ClubWeGo/videomicro/kitex_gen/videomicro" | ||
) | ||
|
||
// Videos 将 videomicro.Video 列表转换为 core.Video 列表,针对每个用户,需要预先把用户对每个视频id的点赞状态和对作者id的关注状态传入 | ||
func Videos(videos []*videomicro.Video, authors []*usermicro.UserInfo, isFavorites map[int64]bool, isFollows map[int64]bool) []*core.Video { | ||
// 一个用户 id 对应一个用户信息,方便后续查询根据视频的作者 id 查询作者信息 | ||
authorMap := make(map[int64]*usermicro.UserInfo, len(authors)) | ||
for _, a := range authors { | ||
authorMap[a.Id] = a | ||
} | ||
|
||
var res []*core.Video | ||
for _, v := range videos { | ||
res = append(res, Video(v, authorMap[v.AuthorId], isFavorites[v.Id], isFollows[v.AuthorId])) | ||
} | ||
return res | ||
} | ||
|
||
// Video 将 videomicro.Video 转换为 core.Video,针对每个用户,需要预先把用户对视频的点赞状态和对作者的关注状态传入 | ||
func Video(video *videomicro.Video, author *usermicro.UserInfo, isFavorite bool, isFollow bool) *core.Video { | ||
return &core.Video{ | ||
ID: video.Id, | ||
Author: User(author, isFollow), | ||
PlayURL: video.PlayUrl, | ||
CoverURL: video.CoverUrl, | ||
FavoriteCount: video.FavoriteCount, | ||
CommentCount: video.CommentCount, | ||
IsFavorite: isFavorite, | ||
Title: video.Title, | ||
} | ||
} |