-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.go
41 lines (38 loc) · 1.02 KB
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package favoriteaction
import (
"context"
"github.com/PICOF/simple-tiktok/cmd/feed/rpc"
"github.com/PICOF/simple-tiktok/dal/operation"
"github.com/PICOF/simple-tiktok/kitex_gen/feed"
)
func ConvertVideoInfo(ctx context.Context, userId int64, info operation.TVideoInfo) (res *feed.VideoInfo, err error) {
author, err := rpc.GetUserInfo(ctx, userId, info)
if err != nil {
return
}
isFavorite, err := operation.IsFavorite(ctx, userId, info.Id)
if err != nil {
return
}
res = &feed.VideoInfo{
Id: info.Id,
Author: author,
PlayUrl: info.PlayUrl,
CoverUrl: info.CoverUrl,
FavoriteCount: info.FavoriteCount,
CommentCount: info.CommentCount,
IsFavorite: isFavorite,
Title: info.Title,
}
return
}
func ConvertAllVideoInfo(ctx context.Context, userId int64, list []operation.TVideoInfo) (res []*feed.VideoInfo, err error) {
for _, t := range list {
info, err := ConvertVideoInfo(ctx, userId, t)
if err != nil {
return nil, err
}
res = append(res, info)
}
return
}