-
Notifications
You must be signed in to change notification settings - Fork 10
/
comment.go
125 lines (120 loc) · 2.8 KB
/
comment.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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/comment"
)
func CommentAction(ctx context.Context, c *app.RequestContext) {
token := c.Query("token")
vid, err := strconv.ParseInt(c.Query("video_id"), 10, 64)
if err != nil {
c.JSON(http.StatusOK, response.CommentAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: "video_id 不合法",
},
Comment: nil,
})
return
}
actionType, err := strconv.ParseInt(c.Query("action_type"), 10, 64)
if err != nil || (actionType != 1 && actionType != 2) {
c.JSON(http.StatusOK, response.CommentAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: "action_type 不合法",
},
Comment: nil,
})
return
}
req := new(kitex.CommentActionRequest)
req.Token = token
req.VideoId = vid
req.ActionType = int32(actionType)
if actionType == 1 {
commentText := c.Query("comment_text")
if commentText == "" {
c.JSON(http.StatusOK, response.CommentAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: "comment_text 不能为空",
},
Comment: nil,
})
return
}
req.CommentText = commentText
} else if actionType == 2 {
commentID, err := strconv.ParseInt(c.Query("comment_id"), 10, 64)
if err != nil {
c.JSON(http.StatusOK, response.CommentAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: "comment_id 不合法",
},
Comment: nil,
})
return
}
req.CommentId = commentID
}
res, _ := rpc.CommentAction(ctx, req)
if res.StatusCode == -1 {
c.JSON(http.StatusOK, response.CommentAction{
Base: response.Base{
StatusCode: -1,
StatusMsg: res.StatusMsg,
},
Comment: nil,
})
return
}
c.JSON(http.StatusOK, response.CommentAction{
Base: response.Base{
StatusCode: 0,
StatusMsg: res.StatusMsg,
},
Comment: res.Comment,
})
}
func CommentList(ctx context.Context, c *app.RequestContext) {
token := c.Query("token")
vid, err := strconv.ParseInt(c.Query("video_id"), 10, 64)
if err != nil {
c.JSON(http.StatusOK, response.CommentList{
Base: response.Base{
StatusCode: -1,
StatusMsg: "video_id 不合法",
},
CommentList: nil,
})
return
}
req := &kitex.CommentListRequest{
Token: token,
VideoId: vid,
}
res, _ := rpc.CommentList(ctx, req)
if res.StatusCode == -1 {
c.JSON(http.StatusOK, response.CommentList{
Base: response.Base{
StatusCode: -1,
StatusMsg: res.StatusMsg,
},
CommentList: nil,
})
return
}
c.JSON(http.StatusOK, response.CommentList{
Base: response.Base{
StatusCode: 0,
StatusMsg: res.StatusMsg,
},
CommentList: res.CommentList,
})
}