Files
web_hgdjc_server/app/api/commentapi/comment.go
T
2026-11-07 10:44:09 +08:00

87 lines
2.9 KiB
Go

package commentapi
import (
"videoweb/app/api/proto"
"videoweb/app/service/commentser"
"videoweb/pub/common"
"videoweb/pub/common/ipaddr"
"videoweb/pub/common/srvdef"
"github.com/gin-gonic/gin"
)
// SendComment 发布评论
// @Tags 评论APP
// @Summary 发布评论 --by 王鸣
// @Description 发布短剧、短剧剧集或视频评论,parentsId为0发布一级评论,大于0发布二级评论,replyCommentId表示实际回复的评论,objectType 10-短剧 11-短剧剧集 20-视频
// @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
}
ip := ipaddr.ResolveClientIP(ctx)
err := commentser.SendComment(ctx, common.GetUserId(ctx), ip, &in)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, "success")
}
// List 评论列表
// @Tags 评论APP
// @Summary 评论列表 --by 王鸣
// @Description 分页查询短剧、短剧剧集或视频评论树,一级评论分页返回,二级评论挂在children中,objectType 10-短剧 11-短剧剧集 20-视频
// @Accept json
// @Produce json
// @Param params query proto.GetCommentListReq true "评论列表请求"
// @Success 200 {object} proto.GetCommentListResp{list=[]proto.CommentInfo} "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Router /api/app/comment/list [get]
func List(ctx *gin.Context) {
var in proto.GetCommentListReq
if err := ctx.ShouldBindQuery(&in); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := commentser.GetCommentPage(ctx, common.GetUserId(ctx), &in)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// SetLike 评论点赞/取消点赞
// @Tags 评论APP
// @Summary 评论点赞/取消点赞 --by 王鸣
// @Description 设置当前用户对短剧、短剧剧集或视频评论的点赞状态
// @Accept json
// @Produce json
// @Param param body proto.CommentLikeSetReq true "评论点赞设置请求"
// @Success 200 {object} proto.CommentLikeSetResp "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/app/comment/like/set [post]
func SetLike(ctx *gin.Context) {
var in proto.CommentLikeSetReq
if err := ctx.ShouldBindJSON(&in); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := commentser.SetCommentLike(ctx, common.GetUserId(ctx), &in)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}