diff --git a/app/controller/topic/topic.go b/app/controller/topic/topic.go index 0160171..c5d787e 100644 --- a/app/controller/topic/topic.go +++ b/app/controller/topic/topic.go @@ -2,9 +2,11 @@ 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" ) @@ -40,3 +42,59 @@ 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, + }) +} diff --git a/app/logic/topic/topic.go b/app/logic/topic/topic.go index 7d32967..da5df29 100644 --- a/app/logic/topic/topic.go +++ b/app/logic/topic/topic.go @@ -42,15 +42,26 @@ func (t *Topic) GetListByIds(topicIds []uint) (result *[]topic.Topic) { return } +type replyTopicInfo struct { + topic.Topic + IsFollow int `json:"isFollow"` +} + // @Title 根据id获取单条信息 -func (t *Topic) GetInfo(topicId uint) (result topic.Topic) { +func (t *Topic) GetInfo(userId, topicId uint) (result *replyTopicInfo) { + result = &replyTopicInfo{} if topicId <= 0 { return } topicModel := &topic.Topic{} - return topicModel.GetById(topicId) -} - -func (t *Topic) ContentList(topicId uint) { - + result.Topic = topicModel.GetById(topicId) + if result.Id > 0 { + // 获取关注相关 + topicFollow := &topic.TopicFollow{} + followInfo := topicFollow.GetByUserIdAndTopicId(userId, topicId) + if followInfo.Id > 0 && followInfo.IsDel == 0 { + result.IsFollow = 1 + } + } + return } diff --git a/app/router/router.go b/app/router/router.go index 7d5958a..460ea37 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -67,6 +67,9 @@ func Router(router *gin.Engine) { topicR.POST("list", topicC.List) // 话题列表 topicR.POST("hot", topicC.Hot) // 热门话题 + topicR.POST("info", middleware.BothAuth(), topicC.Info) // 热门话题 + topicR.POST("content/list", middleware.BothAuth(), topicC.ContentList) // 热门话题 + followC := &topic.Follow{} topicR.POST("follow/list", middleware.BothAuth(), followC.List) }