-
Notifications
You must be signed in to change notification settings - Fork 6
/
handler.go
51 lines (41 loc) · 1.61 KB
/
handler.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
42
43
44
45
46
47
48
49
50
51
package main
import (
"context"
"github.com/chenmengangzhi29/douyin/cmd/favorite/service"
"github.com/chenmengangzhi29/douyin/dal/pack"
"github.com/chenmengangzhi29/douyin/kitex_gen/favorite"
"github.com/chenmengangzhi29/douyin/pkg/errno"
)
// FavoriteServiceImpl implements the last service interface defined in the IDL.
type FavoriteServiceImpl struct{}
// FavoriteAction implements the FavoriteServiceImpl interface.
func (s *FavoriteServiceImpl) FavoriteAction(ctx context.Context, req *favorite.FavoriteActionRequest) (resp *favorite.FavoriteActionResponse, err error) {
resp = new(favorite.FavoriteActionResponse)
if len(req.Token) == 0 || req.VideoId == 0 || req.ActionType == 0 {
resp.BaseResp = pack.BuildFavoriteBaseResp(errno.ParamErr)
return resp, nil
}
err = service.NewFavoriteActionService(ctx).FavoriteAction(req)
if err != nil {
resp.BaseResp = pack.BuildFavoriteBaseResp(err)
return resp, nil
}
resp.BaseResp = pack.BuildFavoriteBaseResp(errno.Success)
return resp, nil
}
// FavoriteList implements the FavoriteServiceImpl interface.
func (s *FavoriteServiceImpl) FavoriteList(ctx context.Context, req *favorite.FavoriteListRequest) (resp *favorite.FavoriteListResponse, err error) {
resp = new(favorite.FavoriteListResponse)
if req.UserId == 0 {
resp.BaseResp = pack.BuildFavoriteBaseResp(errno.ParamErr)
return resp, nil
}
videoList, err := service.NewFavoriteListService(ctx).FavoriteList(req)
if err != nil {
resp.BaseResp = pack.BuildFavoriteBaseResp(err)
return resp, nil
}
resp.BaseResp = pack.BuildFavoriteBaseResp(errno.Success)
resp.VideoList = videoList
return resp, nil
}