7 Star 2 Fork 2

赵康铭 / tinyTicktok

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
comment.go 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
weirdo0314 提交于 2022-06-10 10:05 . chore:style code
package api
import (
"gitee.com/zhaokangming/tiny-ticktok/model"
"gitee.com/zhaokangming/tiny-ticktok/pkg/app"
"gitee.com/zhaokangming/tiny-ticktok/pkg/constants"
"gitee.com/zhaokangming/tiny-ticktok/pkg/errcode"
"gitee.com/zhaokangming/tiny-ticktok/pkg/util/auth"
"gitee.com/zhaokangming/tiny-ticktok/pkg/util/convert"
"gitee.com/zhaokangming/tiny-ticktok/service"
"github.com/gin-gonic/gin"
)
// CommentListResponse comment list response
type CommentListResponse struct {
model.Response
CommentList []model.Comment `json:"comment_list,omitempty"`
}
// CommentAction create or delete a comment
func CommentAction(c *gin.Context) {
claims, ok := c.Value("claims").(*auth.Claims)
if !ok {
app.WriteResponse(c, errcode.ErrAuthCheckToken, nil)
return
}
action, ok := c.GetQuery("action_type")
if !ok {
app.WriteResponse(c, errcode.ErrParamTypeError, nil)
return
}
vid, ok := c.GetQuery("video_id")
if !ok {
app.WriteResponse(c, errcode.ErrParamTypeError, nil)
return
}
if action == constants.Action {
content, ok := c.GetQuery("comment_text")
if !ok {
app.WriteResponse(c, errcode.ErrParamTypeError, nil)
return
}
err := service.CreateComment(c, claims.ID, convert.StrTo(vid).MustInt64(), content)
app.WriteResponse(c, err, nil)
return
}
if action == constants.ActionCancel {
cid, ok := c.GetQuery("comment_id")
if !ok {
app.WriteResponse(c, errcode.ErrParamTypeError, nil)
return
}
err := service.DeleteComment(c, claims.ID, convert.StrTo(cid).MustInt64())
app.WriteResponse(c, err, nil)
return
}
app.WriteResponse(c, errcode.ErrParamTypeError, nil)
}
// CommentList get all comments of a video
func CommentList(c *gin.Context) {
claims, ok := c.Value("claims").(*auth.Claims)
if !ok {
app.WriteResponse(c, errcode.ErrAuthCheckToken, nil)
return
}
vid, ok := c.GetQuery("video_id")
if !ok {
app.WriteResponse(c, errcode.ErrParamTypeError, nil)
return
}
res, err := service.MGetComments(c, claims.ID, convert.StrTo(vid).MustInt64())
app.WriteResponse(c, err, res)
}
Go
1
https://gitee.com/zhaokangming/tiny-ticktok.git
git@gitee.com:zhaokangming/tiny-ticktok.git
zhaokangming
tiny-ticktok
tinyTicktok
dcbaf51081e9

搜索帮助