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.

127 lines
2.4 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/short"
"live/app/logic/topic"
)
type Topic struct {
}
type argsTopicList struct {
Keyword string `json:"keyword" form:"keyword"`
lib.Page
}
// @Title 话题列表
func (t *Topic) List(c *gin.Context) {
args := argsTopicList{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if args.Keyword == "" {
back.Fail(c, "参数不全")
return
}
list, count := (&topic.Topic{}).List(args.Keyword, args.Page)
back.Suc(c, "操作成功", gin.H{
"list": list,
"total": count,
})
}
type argsAdd struct {
Title string `json:"title" form:"title"`
}
// @Title 添加话题
func (t *Topic) Add(c *gin.Context) {
args := argsAdd{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
userId := common.GetUserId(c)
if args.Title == "" {
back.Fail(c, "参数错误")
return
}
topicId, err := (&topic.Topic{}).Add(userId, args.Title)
if err != nil {
back.Fail(c, err.Error())
return
}
back.Suc(c, "操作成功", gin.H{
"topicId": topicId,
})
}
// @Title 话题列表
func (t *Topic) Hot(c *gin.Context) {
list := (&topic.Topic{}).Hot()
back.Suc(c, "操作成功", list)
}
type argsInfo struct {
TopicId uint `json:"topicId" form:"topicId"`
}
// @Title 获取单条详情
func (t *Topic) Info(c *gin.Context) {
uid := common.GetUserId(c)
args := argsInfo{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if args.TopicId <= 0 {
back.Fail(c, "参数不全")
return
}
info := (&topic.Topic{}).GetInfo(uid, args.TopicId)
if info.Id > 0 {
back.Suc(c, "操作成功", info)
return
} else {
back.Fail(c, "未查询到数据")
return
}
}
type argsTopicContentList struct {
TopicId uint `json:"topicId" form:"topicId"`
lib.Page
}
// @Title 话题内容列表
func (t *Topic) ContentList(c *gin.Context) {
uid := common.GetUserId(c)
args := argsTopicContentList{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if args.TopicId <= 0 {
back.Fail(c, "参数不全")
return
}
list, count, err := (&short.Short{}).ListByTopicId(uid, args.TopicId, args.Page)
if err != nil {
back.Err(c, err.Error())
return
}
back.Suc(c, "操作成功", gin.H{
"list": list,
"total": count,
})
}