Commit 2dc38660 authored by Lukas Matt's avatar Lukas Matt

Add ApiComment.Show as new route

parent 371711e1
......@@ -23,6 +23,7 @@ import (
"gopkg.in/ganggo/ganggo.v0/app/jobs"
"gopkg.in/ganggo/api.v0/app/helpers"
federation "gopkg.in/ganggo/federation.v0"
"strconv"
"net/http"
)
......@@ -37,9 +38,79 @@ type ApiComment struct {
ApiHelper
}
/**
* @api {get} /comments/:id Display a specific comment
* @apiName ApiComment.Show
* @apiGroup Comments
*
* @apiParam {Number} id Comment database ID
* @apiParam {String} access_token Oauth access token
*
* @apiSuccess {String} CreatedAt Timestamp of creation
* @apiSuccess {String} UpdatedAt Timestamp of last replacment
* @apiSuccess {String} Guid Unique global ID
* @apiSuccess {Number} ID Unique database ID
* @apiSuccess {String} Text Status message
* @apiSuccess {Number} ShareableID Post database ID
* @apiSuccess {Number} PersonID Person database ID
* @apiSuccess {String} ShareableType Shareable type e.g. Post, Comment
* @apiSuccess {Hash} CommentSignature Signature
* @apiSuccess {Hash} Person Person structure
*
* @apiSuccessExample {json} Success-Response
* HTTP/1.1 200 OK
* {
* "ID": 12,
* "CreatedAt": "2018-01-08T15:25:43Z",
* "UpdatedAt": "2018-01-08T15:25:43Z",
* "Text": "hi",
* "ShareableID": 20,
* "PersonID": 1,
* "Guid": "cc783a9749f09c7d817a1707a4c052bc",
* "LikesCount": 0,
* "ShareableType": "Post",
* [...]
* }
*
* @apiError (Errors) {String} error Contains the recent error message
*
* @apiErrorExample {json} Unauthorized
* HTTP/1.1 401 Unauthorized
* {
* "error": "[...]"
* }
*
* @apiErrorExample {json} NotFound
* HTTP/1.1 404 Not Found
* {
* "error": "[...]"
* }
*
*/
func (c ApiComment) Show() revel.Result {
var (
guid string
comment models.Comment
)
c.Params.Bind(&guid, "id")
id, err := strconv.ParseUint(guid, 10, 32);
if err == nil {
err = comment.FindByUserAndID(c.CurrentUser, uint(id))
} else {
err = comment.FindByUserAndGuid(c.CurrentUser, guid)
}
if err != nil {
c.Log.Error(TAG, "db", err, "api", ERR_NOT_FOUND)
return c.ApiError(http.StatusNotFound, ERR_NOT_FOUND)
}
return c.RenderJSON(comment)
}
/**
* @api {get} /posts/:id/comments Display comments related to post
* @apiName ApiComment.Index
* @apiName ApiComment.IndexPost
* @apiGroup Comments
*
* @apiParam {Number} id Post database ID
......@@ -88,7 +159,7 @@ type ApiComment struct {
* }
*
*/
func (c ApiComment) Index() revel.Result {
func (c ApiComment) IndexPost() revel.Result {
var (
postID uint
comments models.Comments
......@@ -105,7 +176,7 @@ func (c ApiComment) Index() revel.Result {
/**
* @api {post} /posts/:id/comments Create comment on post
* @apiName ApiComment.Create
* @apiName ApiComment.CreatePost
* @apiGroup Comments
*
* @apiParam {Number} id Post database ID
......@@ -134,7 +205,7 @@ func (c ApiComment) Index() revel.Result {
* }
*
*/
func (c ApiComment) Create() revel.Result {
func (c ApiComment) CreatePost() revel.Result {
var (
comment, fields string
postID uint
......@@ -169,10 +240,6 @@ func (c ApiComment) Create() revel.Result {
return c.RenderJSON(post)
}
func (c ApiComment) Show() revel.Result {
return c.NotFound("Not implemented yet")
}
func (c ApiComment) Delete() revel.Result {
return c.NotFound("Not implemented yet")
}
......@@ -19,8 +19,9 @@ POST /api/v0/posts/:id/likes/:positive ApiLike.Create
#GET /api/v0/posts/:id/likes/:like_id ApiLike.Show
#DELETE /api/v0/posts/:id/likes/:like_id ApiLike.Delete
GET /api/v0/posts/:id/comments ApiComment.Index
POST /api/v0/posts/:id/comments ApiComment.Create
GET /api/v0/comments/:id ApiComment.Show
GET /api/v0/posts/:id/comments ApiComment.IndexPost
POST /api/v0/posts/:id/comments ApiComment.CreatePost
#GET /api/v0/posts/:id/comments/:comment_id ApiComment.Show
#DELETE /api/v0/posts/:id/comments/:comment_id ApiComment.Delete
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment