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.
101 lines
1.9 KiB
101 lines
1.9 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,
|
|
})
|
|
}
|
|
|
|
// @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,
|
|
})
|
|
}
|