Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

feature: add API to get comment by its id (#642)

Guilherme Oenning76ea3a1638fa
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index c1435f4fc..01f80410e 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -154,8 +154,9 @@ func routes(r *web.Engine) *web.Engine {
{
api.Get("/api/v1/posts", apiv1.SearchPosts())
api.Get("/api/v1/tags", apiv1.ListTags())
- api.Get("/api/v1/posts/:number/comments", apiv1.ListComments())
api.Get("/api/v1/posts/:number", apiv1.GetPost())
+ api.Get("/api/v1/posts/:number/comments", apiv1.ListComments())
+ api.Get("/api/v1/posts/:number/comments/:id", apiv1.GetComment())
//From this step, a User is required
api.Use(middlewares.IsAuthenticated())
diff --git a/app/handlers/apiv1/post.go b/app/handlers/apiv1/post.go
index 8cfa1085a..6138fd474 100644
--- a/app/handlers/apiv1/post.go
+++ b/app/handlers/apiv1/post.go
@@ -159,6 +159,23 @@ func ListComments() web.HandlerFunc {
}
}
+// GetComment returns a single comment by its ID
+func GetComment() web.HandlerFunc {
+ return func(c web.Context) error {
+ id, err := c.ParamAsInt("id")
+ if err != nil {
+ return c.NotFound()
+ }
+
+ comment, err := c.Services().Posts.GetCommentByID(id)
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ return c.Ok(comment)
+ }
+}
+
// PostComment creates a new comment on given post
func PostComment() web.HandlerFunc {
return func(c web.Context) error {