-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcomment.go
66 lines (61 loc) · 1.51 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
package controller
import (
"douyin/global"
"douyin/logic"
"douyin/models"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http"
)
type CommentListResponse struct {
Response
CommentList []models.Comment `json:"comment_list,omitempty"`
}
type CommentActionResponse struct {
Response
Comment models.Comment `json:"comment,omitempty"`
}
// CommentAction insert or update or delete comment
func CommentAction(c *gin.Context) {
param := new(models.ParamCommentAction)
user, _ := c.Get("auth")
c.ShouldBindQuery(param)
comment, err := logic.DoComment(param)
if err != nil {
global.Logger.Error("can't create comment", zap.Error(err))
c.JSON(http.StatusOK, Response{
StatusCode: 500,
StatusMsg: CodeMap[CodeInternalError],
})
return
}
c.JSON(http.StatusOK, CommentActionResponse{
Response: Response{
StatusCode: 0,
StatusMsg: "评论成功!",
},
Comment: models.Comment{
Id: comment.Id,
User: user.(models.User),
Content: comment.Content,
CreateDate: comment.CreatedAt.Format("01-03"),
}},
)
}
// CommentList Get all comments
func CommentList(c *gin.Context) {
param := new(models.ParamCommentList)
c.ShouldBindQuery(param)
comments, err := logic.GetCommentList(param)
if err != nil {
global.Logger.Error("Can't get comments ", zap.Error(err))
c.JSON(http.StatusOK, CodeMap[CodeInternalError])
}
c.JSON(http.StatusOK, CommentListResponse{
Response: Response{
StatusCode: 0,
StatusMsg: "获取评论成功!",
},
CommentList: comments,
})
}