-
Notifications
You must be signed in to change notification settings - Fork 9
/
favorite.go
94 lines (88 loc) · 2.07 KB
/
favorite.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package handler
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
"net/http"
"strconv"
"github.com/bytedance-youthcamp-jbzx/tiktok/cmd/api/rpc"
"github.com/bytedance-youthcamp-jbzx/tiktok/internal/response"
kitex "github.com/bytedance-youthcamp-jbzx/tiktok/kitex/kitex_gen/favorite"
)
func FavoriteAction(ctx context.Context, c *app.RequestContext) {
token := c.Query("token")
actionType, err := strconv.ParseInt(c.Query("action_type"), 10, 64)
if err != nil || (actionType != 1 && actionType != 2) {
c.JSON(http.StatusOK, response.FavoriteAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: "action_type 不合法",
},
})
return
}
vid, err := strconv.ParseInt(c.Query("video_id"), 10, 64)
if err != nil {
c.JSON(http.StatusOK, response.FavoriteAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: "video_id 不合法",
},
})
return
}
req := &kitex.FavoriteActionRequest{
Token: token,
VideoId: vid,
ActionType: int32(actionType),
}
res, _ := rpc.FavoriteAction(ctx, req)
if res.StatusCode == -1 {
c.JSON(http.StatusOK, response.FavoriteAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: res.StatusMsg,
},
})
return
}
c.JSON(http.StatusOK, response.FavoriteAction{
Base: response.Base{
StatusCode: 0,
StatusMsg: res.StatusMsg,
},
})
}
func FavoriteList(ctx context.Context, c *app.RequestContext) {
token := c.Query("token")
uid, err := strconv.ParseInt(c.Query("user_id"), 10, 64)
if err != nil {
c.JSON(http.StatusOK, response.FavoriteList{
Base: response.Base{
StatusCode: -1,
StatusMsg: "user_id 不合法",
},
})
return
}
req := &kitex.FavoriteListRequest{
UserId: uid,
Token: token,
}
res, _ := rpc.FavoriteList(ctx, req)
if res.StatusCode == -1 {
c.JSON(http.StatusOK, response.FavoriteList{
Base: response.Base{
StatusCode: -1,
StatusMsg: res.StatusMsg,
},
})
return
}
c.JSON(http.StatusOK, response.FavoriteList{
Base: response.Base{
StatusCode: 0,
StatusMsg: res.StatusMsg,
},
VideoList: res.VideoList,
})
}