/
POST_comments.go
45 lines (36 loc) · 1002 Bytes
/
POST_comments.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
package routes
import (
"context"
"net/http"
"strconv"
videoproto "github.com/horahoradev/horahora/video_service/protocol"
"github.com/labstack/echo/v4"
)
// Route: POST /comments/
// Requires authentication
// Accepts form-encoded values: video_id, content (content of comment), and parent (parent comment id if a reply)
// response: 200 if ok
func (r RouteHandler) handleComment(c echo.Context) error {
videoID := c.FormValue("video_id")
profile, err := r.getUserProfileInfo(c)
if err != nil {
return err
}
content := c.FormValue("content")
videoIDInt, err := strconv.ParseInt(videoID, 10, 64)
if err != nil {
return err
}
parent := c.FormValue("parent")
parentIDInt, _ := strconv.ParseInt(parent, 10, 64)
_, err = r.v.MakeComment(context.Background(), &videoproto.VideoComment{
UserId: profile.UserID,
VideoId: videoIDInt,
Comment: content,
ParentComment: parentIDInt,
})
if err != nil {
return err
}
return c.JSON(http.StatusOK, nil)
}