Skip to content

Commit

Permalink
话题详情 api
Browse files Browse the repository at this point in the history
  • Loading branch information
Away0x committed May 18, 2019
1 parent 102b3a1 commit 0e208ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/controllers/api/topic/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/api/topic/utils__.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions routes/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 0e208ae

Please sign in to comment.