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.

67 lines
1.2 KiB

package trend
import (
"github.com/gin-gonic/gin"
"live/app/common"
"live/app/lib/back"
"live/app/lib/tools"
"live/app/logic/user/trend"
)
type Praise struct {
}
type argsPraise struct {
TrendId uint `json:"trendId" form:"trendId"`
}
// @Title 点赞
func (p *Praise) Add(c *gin.Context) {
uid := common.GetUserId(c)
if uid == 0 {
back.Fail(c, "未登录")
return
}
args := argsPraise{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if args.TrendId <= 0 {
back.Fail(c, "参数错误")
return
}
err := (&trend.Praise{}).AddPraise(uid, args.TrendId)
if err != nil {
back.Fail(c, err.Error())
return
}
back.Suc(c, "操作成功", "")
return
}
// @Title 取消点赞
func (p *Praise) Cancel(c *gin.Context) {
uid := common.GetUserId(c)
if uid == 0 {
back.Fail(c, "未登录")
return
}
args := argsPraise{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if args.TrendId <= 0 {
back.Fail(c, "参数错误")
return
}
err := (&trend.Praise{}).CancelPraise(uid, args.TrendId)
if err != nil {
back.Fail(c, err.Error())
return
}
back.Suc(c, "操作成功", "")
return
}