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.
94 lines
1.8 KiB
94 lines
1.8 KiB
package topic
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"live/app/common"
|
|
"live/app/lib"
|
|
"live/app/lib/back"
|
|
"live/app/lib/tools"
|
|
"live/app/logic/topic"
|
|
)
|
|
|
|
type Follow struct {
|
|
}
|
|
|
|
type argsList struct {
|
|
FindUserId uint `json:"findUserId" form:"findUserId"`
|
|
lib.Page
|
|
}
|
|
|
|
// @Title 会员话题关注列表
|
|
// @Param FindUserId uint true "需要查询的会员id"
|
|
func (f *Follow) List(c *gin.Context) {
|
|
uid := common.GetUserId(c)
|
|
args := argsList{}
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
if args.FindUserId <= 0 {
|
|
back.Fail(c, "参数错误")
|
|
return
|
|
}
|
|
list, count := (&topic.Follow{}).GetList(uid, args.FindUserId, args.Page)
|
|
|
|
back.Suc(c, "操作成功", gin.H{
|
|
"list": list,
|
|
"total": count,
|
|
})
|
|
}
|
|
|
|
type argsFollowChange struct {
|
|
TopicId uint `json:"topicId" form:"topicId"`
|
|
}
|
|
|
|
// @Title 添加关注
|
|
func (f *Follow) Add(c *gin.Context) {
|
|
uid := common.GetUserId(c)
|
|
if uid == 0 {
|
|
back.Fail(c, "未登录")
|
|
return
|
|
}
|
|
args := argsFollowChange{}
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
if args.TopicId <= 0 {
|
|
back.Fail(c, "参数错误")
|
|
return
|
|
}
|
|
flag := (&topic.Follow{}).Add(uid, args.TopicId)
|
|
if flag {
|
|
back.Suc(c, "关注成功", "")
|
|
return
|
|
} else {
|
|
back.Fail(c, "关注失败")
|
|
}
|
|
}
|
|
|
|
// @Title 取消关注
|
|
func (f *Follow) Cancel(c *gin.Context) {
|
|
uid := common.GetUserId(c)
|
|
if uid == 0 {
|
|
back.Fail(c, "未登录")
|
|
return
|
|
}
|
|
args := argsFollowChange{}
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
if args.TopicId <= 0 {
|
|
back.Fail(c, "参数错误")
|
|
return
|
|
}
|
|
flag := (&topic.Follow{}).Cancel(uid, args.TopicId)
|
|
if flag {
|
|
back.Suc(c, "取关成功", "")
|
|
return
|
|
} else {
|
|
back.Fail(c, "取关失败")
|
|
}
|
|
}
|