Files
2026-10-26 16:28:14 +08:00

103 lines
2.8 KiB
Go

package commentapi
import (
"videoweb/app/api/proto"
"videoweb/app/service/commentser"
"videoweb/pub/common"
"videoweb/pub/common/enum/consts"
"videoweb/pub/common/srvdef"
"github.com/gin-gonic/gin"
)
// List 评论列表
// @Tags 评论APP
// @Summary 评论列表 -- by 王鸣
// @Description 按对象查询树形评论列表
// @Accept json
// @Produce json
// @Param params query proto.CommentListReq true "评论列表请求"
// @Success 200 {object} proto.CommentListResp{list=[]proto.CommentInfo} "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Router /api/app/comment/list [get]
func List(ctx *gin.Context) {
var req proto.CommentListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := commentser.ListCommentTree(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// SendComment 发布评论
// @Tags 评论APP
// @Summary 发布评论 -- by 王鸣
// @Description 发布评论
// @Accept json
// @Produce json
// @Param param body proto.CommentSendReq true "参数列表"
// @Success 200 {object} string "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/app/comment/send [post]
func SendComment(ctx *gin.Context) {
var in proto.CommentSendReq
if err := ctx.ShouldBindJSON(&in); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
userId, exists := ctx.Get(consts.CtxUserID)
if !exists {
common.ServerJSON(ctx, srvdef.InvalidToken, nil)
return
}
userIdInt64, ok := userId.(int64)
if !ok || userIdInt64 <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, nil)
return
}
ip := ctx.ClientIP()
ua, _ := common.GetUA(ctx)
err := commentser.SendComment(ctx, ip, userIdInt64, &in, ua)
if err != nil {
common.ServerJSON(ctx, err.Code, "")
return
}
common.ServerJSON(ctx, srvdef.Success, "success")
}
// SetLike 设置评论点赞状态
// @Tags 评论APP
// @Summary 评论点赞/取消点赞 -- by 王鸣
// @Accept json
// @Produce json
// @Param param body proto.CommentLikeSetReq true "点赞参数"
// @Success 200 {object} proto.CommentLikeSetResp "成功"
// @Security ApiKeyAuth
// @Router /api/app/comment/like/set [post]
func SetLike(ctx *gin.Context) {
var req proto.CommentLikeSetReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
userId := common.GetUserId(ctx)
if userId <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, nil)
return
}
resp, err := commentser.SetCommentLike(ctx, userId, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}