You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.5 KiB

package trend
import (
"github.com/gin-gonic/gin"
"live/app/common"
"live/app/lib"
"live/app/lib/back"
"live/app/lib/tools"
"live/app/logic/user/trend"
)
type Comment struct {
}
type argsCommentList struct {
TrendId uint `json:"trendId" form:"trendId"`
ParentId uint `json:"parentId" form:"parentId"` // 非空获取子评论列表
lib.Page
}
// @Title 评论列表
func (c *Comment) List(ctx *gin.Context) {
uid := common.GetUserId(ctx)
args := argsCommentList{}
if err := tools.ParseParams(&args, ctx); err != nil {
back.Fail(ctx, err.Error())
return
}
if args.TrendId <= 0 {
back.Fail(ctx, "参数错误")
return
}
list, count := (&trend.Comment{}).List(uid, args.TrendId, args.ParentId, args.Page)
back.Suc(ctx, "操作成功", gin.H{
"list": list,
"count": count,
})
return
}
type argsCommentAdd struct {
TrendId uint `json:"trendId" form:"trendId"`
ParentId uint `json:"parentId" form:"parentId"` // 非空获取子评论列表
Content string `json:"content" form:"content"`
}
// @Title 添加评论
func (c *Comment) Add(ctx *gin.Context) {
uid := common.GetUserId(ctx)
if uid == 0 {
back.Fail(ctx, "未登录")
return
}
args := argsCommentAdd{}
if err := tools.ParseParams(&args, ctx); err != nil {
back.Fail(ctx, err.Error())
return
}
if args.TrendId <= 0 || args.Content == "" {
back.Fail(ctx, "参数错误")
return
}
err := (&trend.Comment{}).Add(uid, args.TrendId, args.ParentId, args.Content)
if err != nil {
back.Fail(ctx, err.Error())
return
}
back.Suc(ctx, "评论成功", "")
return
}