diff --git a/app/controllers/api/topic/resource.go b/app/controllers/api/topic/resource.go index da54bcf..b3ee999 100644 --- a/app/controllers/api/topic/resource.go +++ b/app/controllers/api/topic/resource.go @@ -35,6 +35,16 @@ func UserIndex(c *gin.Context, currentUser *userModel.User, tokenString string) }) } +// Show topic detail +func Show(c *gin.Context) { + topic, _, ok := getTopic(c, nil) + if !ok { + return + } + + controllers.SendOKResponse(c, viewmodels.TopicApi(topic)) +} + // Store 发布 topic func Store(c *gin.Context, currentUser *userModel.User, tokenString string) { var req request.Store diff --git a/app/controllers/api/topic/utils__.go b/app/controllers/api/topic/utils__.go index f67bb05..3334113 100644 --- a/app/controllers/api/topic/utils__.go +++ b/app/controllers/api/topic/utils__.go @@ -26,8 +26,10 @@ func getTopic(c *gin.Context, currentUser *userModel.User) (*topicModel.Topic, i } // 权限 - if ok := policies.TopicPolicyOwner(c, currentUser, int(topic.UserID)); !ok { - return nil, id, false + if currentUser != nil { + if ok := policies.TopicPolicyOwner(c, currentUser, int(topic.UserID)); !ok { + return nil, id, false + } } return topic, id, true diff --git a/routes/api.go b/routes/api.go index 515eb46..ad8f887 100644 --- a/routes/api.go +++ b/routes/api.go @@ -89,5 +89,7 @@ func registerAPI(r *router.MyRoute, middlewares ...gin.HandlerFunc) { wrapper.GetToken(topic.Destroy)) // 话题列表 topicRouter.Register("GET", "api.topics.index", "", topic.Index) + // 话题详情 + topicRouter.Register("GET", "api.topics.show", "/:id", topic.Show) } }