Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

fix: token and latest time can't be empty #100

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/api/biz/handler/api/basic_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions cmd/video/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ type VideoServiceImpl struct{}
// Feed implements the VideoServiceImpl interface.
func (s *VideoServiceImpl) Feed(ctx context.Context, req *video.FeedRequest) (resp *video.FeedResponse, err error) {
resp = new(video.FeedResponse)
if req.LatestTime == 0 {
req.LatestTime = time.Now().Unix()
if req.LatestTime == nil {
currentTime := time.Now().Unix()
req.LatestTime = &currentTime
}
if req.Token == "" {
req.Token, err = utils.CreateToken(10000)
if req.Token == nil {
req.Token = new(string)
*req.Token, err = utils.CreateToken(10000)
if err != nil {
resp.Base = pack.BuildBaseResp(errno.ParamError)
}
}
if _, err := utils.CheckToken(req.Token); err != nil {
if _, err := utils.CheckToken(*req.Token); err != nil {
resp.Base = pack.BuildBaseResp(errno.AuthorizationFailedError)
return resp, nil
}
Expand Down Expand Up @@ -159,12 +161,12 @@ func (s *VideoServiceImpl) PutVideo(ctx context.Context, req *video.PutVideoRequ
// 上传视频
eg.Go(func() error {
err = service.NewVideoService(ctx).UploadVideo(req, videoName)
return err
return errno.FileUploadError
})
// 截取并上传封面
eg.Go(func() error {
err = service.NewVideoService(ctx).UploadCover(req, coverName)
return err
return errno.FileUploadError
})
// 将视频数据写入数据库
eg.Go(func() error {
Expand Down
16 changes: 8 additions & 8 deletions cmd/video/service/feed_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ func (s *VideoService) FeedVideo(req *video.FeedRequest) ([]db.Video, []*user.Us
var videoList []db.Video
var err error

if exist, err := cache.IsExistVideoInfo(s.ctx, req.LatestTime); exist == 1 {
if exist, err := cache.IsExistVideoInfo(s.ctx, *req.LatestTime); exist == 1 {
if err != nil {
return nil, nil, nil, nil, nil, err
}
videoList, err = cache.GetVideoList(s.ctx, req.LatestTime)
videoList, err = cache.GetVideoList(s.ctx, *req.LatestTime)
if err != nil {
return nil, nil, nil, nil, nil, err
}
} else {
formattedTime := time.Unix(req.LatestTime, 0).Format("2006-01-02 15:04:05")
formattedTime := time.Unix(*req.LatestTime, 0).Format("2006-01-02 15:04:05")
videoList, err := db.GetVideoInfoByTime(s.ctx, formattedTime)
if err != nil {
return nil, nil, nil, nil, nil, err
}
go cache.AddVideoList(s.ctx, videoList, req.LatestTime)
go cache.AddVideoList(s.ctx, videoList, *req.LatestTime)
}
// 创建错误组
var eg errgroup.Group
Expand All @@ -46,7 +46,7 @@ func (s *VideoService) FeedVideo(req *video.FeedRequest) ([]db.Video, []*user.Us
// 获取user信息
userInfo, err := rpc.GetUser(s.ctx, &user.InfoRequest{
UserId: videoList[index].UserID,
Token: req.Token,
Token: *req.Token,
})
if err == nil {
userResults <- userInfo
Expand All @@ -57,7 +57,7 @@ func (s *VideoService) FeedVideo(req *video.FeedRequest) ([]db.Video, []*user.Us
// 获取favoriteCount
favoriteCount, err := rpc.GetVideoFavoriteCount(s.ctx, &interaction.VideoFavoritedCountRequest{
VideoId: videoList[index].Id,
Token: req.Token,
Token: *req.Token,
})
if err == nil {
favoriteCountResults <- favoriteCount
Expand All @@ -68,7 +68,7 @@ func (s *VideoService) FeedVideo(req *video.FeedRequest) ([]db.Video, []*user.Us
// 获取commentCount
commentCount, err := rpc.GetCommentCount(s.ctx, &interaction.CommentCountRequest{
VideoId: videoList[index].Id,
Token: &req.Token,
Token: req.Token,
})
if err == nil {
commentCountResults <- commentCount
Expand All @@ -80,7 +80,7 @@ func (s *VideoService) FeedVideo(req *video.FeedRequest) ([]db.Video, []*user.Us
isFavorite, err := rpc.GetVideoIsFavorite(s.ctx, &interaction.InteractionServiceIsFavoriteArgs{Req: &interaction.IsFavoriteRequest{
UserId: videoList[index].UserID,
VideoId: videoList[index].Id,
Token: req.Token,
Token: *req.Token,
}})
if err == nil {
isFavoriteResults <- isFavorite
Expand Down
10 changes: 6 additions & 4 deletions cmd/video/service/feed_video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func TestFeedVideo(t *testing.T) {
t.Fail()
}
videoService := service.NewVideoService(context.Background())
testTime := new(int64)
*testTime = 1693101739
// 第一次从数据库读取,并写入redis
_, _, _, _, _, err = videoService.FeedVideo(&video.FeedRequest{
LatestTime: 1693101739,
Token: token,
LatestTime: testTime,
Token: &token,
})
if err != nil {
t.Error(err)
Expand All @@ -36,8 +38,8 @@ func TestFeedVideo(t *testing.T) {
time.Sleep(time.Second)
// 第二次直接从redis读取
_, _, _, _, _, err = videoService.FeedVideo(&video.FeedRequest{
LatestTime: 1693101739,
Token: token,
LatestTime: testTime,
Token: &token,
})
if err != nil {
t.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions idl/video.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ message Video{
}

message FeedRequest{
int64 latest_time = 1;
string token = 2;
optional int64 latest_time = 1;
optional string token = 2;
}

message FeedResponse{
Expand Down
14 changes: 8 additions & 6 deletions kitex_gen/video/video.pb.fast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading