Skip to content
ahmadumar020 edited this page Apr 28, 2020 · 39 revisions

Posts

Get All Posts

Endpoint: /api/posts
Method : GET
Purpose : Use this API to load all posts stored on the server.

Return Parameters:

Parameter Name Format Purpose
post (array of next) A list of posts with the following fields:
post._id String The post id
post.title String The post title
post.body String The post body
post.author String The id of the post's author
post.sub_thread String The sub thread the post belongs to
post.upvotes_clap Number The number of clap upvotes this post has
post.upvotes_laugh Number The number of laugh upvotes this post has
post.upvotes_sad Number The number of sad upvotes this post has
post.date_created String of ISO time The local time of the user when this post was created
message (optional) String Contains error message (if applicable)

Example:
GET /api/posts

Response:

{
   "post": [
      {
        "upvotes_clap": 0,
        "upvotes_laugh": 0,
        "upvotes_sad": 0,
        "children": [
            "5ea66ea262e1931430026ccc",
            "5ea66f0762e1931430026cce"
        ],
        "_id": "5ea66e8b62e1931430026ccb",
        "title": "New Post in Subthread1",
        "body": "Hey testing this post.",
        "author": "5ea447fb7728645a4421240f",
        "sub_thread": "SubThread1",
        "date_created": "2020-04-27T05:32:59.843Z",
        "updatedAt": "2020-04-27T05:35:03.964Z",
        "__v": 0
    }
  ]
}

Status codes:

200 OK: Occurs when all posts have been found and returned in the response

500 Internal Server Error: Occurs when the request was unsuccessful

New Post

Endpoint: /api/posts
Method : POST
Purpose : Use this API to transmit a new post to the server.

Send parameters:

Parameter Name Format Purpose
Authorisation header String Authorization token of the user
title String The title of the post
body String The body of the post.

Return parameters:

Parameter Name Format Purpose
post (array of next) A list of posts with the following fields:
post._id String The post id
post.title String The post title
post.body String The post body
post.author String The id of the post's author
post.upvotes_clap Number The number of clap upvotes this post has
post.upvotes_laugh Number The number of laugh upvotes this post has
post.upvotes_sad Number The number of sad upvotes this post has
post.date_created String of ISO time The local time of the user when this post was created
message (optional) String Contains error message (if applicable)

Example:
POST /api/posts

Body:

{
  "title": "First post",
  "body": "Hello world!"
}

Response:

{
  "post": [
    {
    "upvotes_clap": 0,
    "upvotes_laugh": 0,
    "upvotes_sad": 0,
    "children": [],
    "_id": "5ea447fb7728645a44212410",
    "title": "Testing 26/04/20",
    "body": "Testing body :)",
    "author": "5ea447fb7728645a4421240f",
    "date_created": "2020-04-25T14:23:55.303Z",
    "updatedAt": "2020-04-25T14:23:55.303Z",
    "__v": 0
    }
  ]
}

Status codes:

201 Created: Occurs when the new post is successfully created and saved to MongoDB

400 Bad Request: Occurs when request is missing information

Get Single Post

Endpoint: /api/posts/{id}
Method : GET
Purpose : Use this API to fetch a single post in detail, including it's comments.

Return parameters:

Parameter Name Format Purpose
_id String The selected post's ID
title String The title of the selected post
body String The body of the selected post
post.author String The id of the post's author
date_created String of ISO time The local time of the user when the post is created
upvotes_clap Number The number of clap upvotes this post has
upvotes_laugh Number The number of laugh upvotes this post has
upvotes_sad Number The number of sad upvotes this post has
comments array of next A list of comments with the following fields:
comments._id String The comment ID
comments.body String The body of the comment
comments.date_created String of ISO time The local time of the user when the comment is created
comment.children Array of comment objects A list of comment objects in response to a comment
message (optional) String Contains error message (if applicable)

Example:
GET /api/posts/426

Response:

{
    "author": "5ea447fb7728645a4421240f",
    "_id": "5ea66e8b62e1931430026ccb",
    "title": "New Post in Subthread1",
    "body": "Hey testing this post.",
    "upvotes_clap": 0,
    "upvotes_laugh": 0,
    "upvotes_sad": 0,
    "date_created": "2020-04-27T05:32:59.843Z",
    "comments": [
        {
            "children": [
                {
                    "children": [],
                    "_id": "5ea66ef862e1931430026ccd",
                    "parentID": "5ea66ea262e1931430026ccc",
                    "body": "first reply to 1st reply",
                    "author": "5ea447fb7728645a4421240f",
                    "date_created": "2020-04-27T05:34:48.756Z",
                    "updatedAt": "2020-04-27T05:34:48.756Z",
                    "__v": 0
                }
            ],
            "_id": "5ea66ea262e1931430026ccc",
            "parentID": "5ea66e8b62e1931430026ccb",
            "body": "first reply ",
            "author": "5ea447fb7728645a4421240f",
            "date_created": "2020-04-27T05:33:22.278Z",
            "updatedAt": "2020-04-27T05:34:48.760Z",
            "__v": 0
        },
        {
            "children": [],
            "_id": "5ea66f0762e1931430026cce",
            "parentID": "5ea66e8b62e1931430026ccb",
            "body": "2nd reply to post in subthread1",
            "author": "5ea447fb7728645a4421240f",
            "date_created": "2020-04-27T05:35:03.963Z",
            "updatedAt": "2020-04-27T05:35:03.963Z",
            "__v": 0
        }
    ]
}

Status codes:

200 OK: Occurs when specific post has been found and returned in the response

404 Not Found: Occurs when requested post doesn't exist

Update Post

Endpoint: /api/posts/{id}
Method : PUT
Purpose : Use this API to update an existing post.
Not all fields will be editable(date_created,id) and will be simply be used for verifying the correct post has been selected.

Send parameters:

Parameter Name Format Purpose
Authorisation header String Authorization token of the user
title String The title of the selected post
body String The body of the selected post

Return parameters:

Parameter Name Format Purpose
message (optional) String Contains error message (if applicable)

Example:
PUT /api/posts/b264784c

Body:

{
   "title": "...",
   "body": "...."
}

Response:

{
  "message": "..."
}

Status codes:

200 OK: Occurs when specific post has been updated

400 Bad Request: Occurs when request is missing information

404 Not Found: Occurs when requested post doesn't exist

Delete Post

Endpoint: /api/posts/{id}
Method : DELETE
Purpose : Use this API to delete an existing post.

Send parameters:

Parameter Name Format Purpose
Authorisation header String Authorization token of the user

Return parameters:

Parameter Name Format Purpose
message (optional) String Contains error message (if applicable)

Example:
DELETE /api/posts/b742685b

Response:

{
  "message": "..."
}

Status codes:

200 OK: Occurs when specific post has been deleted

403 OK: Occurs if you are not the author of the post

404 Not Found: Occurs when requested post doesn't exist

Upvote Post

Endpoint: /api/posts/{id}/upvote
Method : PUT
Purpose : Use this API to upvote an existing post.

Send parameters:

Parameter Name Format Purpose
Authorisation header String Authorization token of the user
upvote_type String The upvote type;"clap","laugh","sad"
upvote Bool Whether this is an upvote or a downvote. '1'-upvote, '0'-downvote

Return parameters:

Parameter Name Format Purpose
_id String The selected post's ID
title String The title of the selected post
author String The author of the post
body String The body of the selected post
date_created String of ISO time The local time of the user when the post is created
upvotes_clap Number The number of clap upvotes this post has
upvotes_laugh Number The number of laugh upvotes this post has
upvotes_sad Number The number of sad upvotes this post has
comments array of next A list of comments with the following fields:
comments._id String The comment ID
comments.body String The body of the comment
comments.date_created String of ISO time The local time of the user when the comment is created
comment.children Array of comment objects A list of comment objects in response to a comment
message (optional) String Contains error message (if applicable)

Example:
PUT /api/posts/426/upvote

Body:

{
   "upvote_type": "clap",
   "upvote": true
}

Response:

{
    "upvotes_clap": 0,
    "upvotes_laugh": 1,
    "upvotes_sad": 0,
    "children": [
        "5ea448557728645a44212411",
        "5ea44a207728645a44212413"
    ],
    "_id": "5ea447fb7728645a44212410",
    "title": "Testing 26/04/20",
    "body": "Testing body :)",
    "author": "5ea447fb7728645a4421240f",
    "date_created": "2020-04-25T14:23:55.303Z",
    "updatedAt": "2020-04-27T06:29:39.470Z",
    "__v": 0
}

Status codes:

200 OK: Occurs when specific post has been updated

400 Bad Request: Occurs when requested upvote type is invalid

Comments

Add Comment

Endpoint: /api/comments
Method : POST
Purpose : Use this API to transmit a new comment to the server.

Send parameters:

Parameter Name Format Purpose
Authorisation header String Authorization token of the user
parentID String The ID of the comment.
body String The body of the comment.

Return parameters:

Parameter Name Format Purpose
message (optional) String Contains error message (if applicable)

Example:
POST /api/comments

Body:

{
  "parentID": "11",
  "body": "Bye world!"
}

Response:

{
  "message": "..."
}

Status codes:

201 Created: Occurs when the new comment is successfully created and saved to MongoDB

400 Bad Request: Occurs when request is missing information

Get a Single Comment

Endpoint: /api/comments/{id}
Method : GET
Purpose : Use this API to retrieve information of an existing comment.

Return parameters:

Parameter Name Format Purpose
comments._id String The comment id
posts._id String The post id
comments.body String The comment body
users._id String The id of author of comment
comments.date_created String of ISO time The local time of the user when this comment was created
comments.updatedAt String of ISO time The local time of the user when this comment was updated
message (optional) String Contains error message (if applicable)

Example:
GET /api/comments/5ea44a207728645a44212413

Response:

{
    "children": [
        "5ea448687728645a44212412"
    ],
    "_id": "5ea448557728645a44212411",
    "parentID": "5ea447fb7728645a44212410",
    "body": "Yea seems to be working with the authentication ",
    "author": "5ea447fb7728645a4421240f",
    "date_created": "2020-04-25T14:25:25.657Z",
    "updatedAt": "2020-04-25T14:25:44.042Z",
    "__v": 0
}

Status codes:

201 OK: Occurs when specific comment has been retrieved

400 Bad Request: Occurs when request is missing information

404 Not Found: Occurs when requested comment doesn't exist

Update Comment

Endpoint: /api/comments/{id}
Method : PUT
Purpose : Use this API to edit an existing comment.

Send parameters:

Parameter Name Format Purpose
Authorisation header String Authorization token of the user
commentBody String The new body text of the selected comment

Return parameters:

Parameter Name Format Purpose
message (optional) String Contains error message (if applicable)

Example:
PUT /api/comments/4536

Body:

{
   "commentBody": "I'm really hungry"
}

Response:

{
  "message": "..."
}

Status codes:

200 OK: Occurs when specific comment has been updated

400 Bad Request: Occurs when request is missing information

404 Not Found: Occurs when requested comment doesn't exist

Delete Comment

Endpoint: /api/comments/{id}
Method : DELETE
Purpose : Use this API to delete an existing comment. Comments with no children will be entirely deleted. Comments with children will have comment body deleted so we can retain nested structure

Send parameters:

Parameter Name Format Purpose
Authorisation header String Authorization token of the user

Return parameters:

Parameter Name Format Purpose
message (optional) String Contains error message (if applicable)

Example:
DELETE /api/comments/b742685b

Response:

{
  "message": "..."
}

Status codes:

200 OK: Occurs when specific comment has been deleted

404 Not Found: Occurs when requested comment doesn't exist

subThreads

Get All subThreads

Endpoint: /api/subThreads
Method : GET
Purpose : Use this API to load all subThreads stored on the server.

Return parameters:

Parameter Name Format Purpose
subThreads._id String The post id
subThreads.title String The post title
message (optional) String Contains error message (if applicable)

Example:
GET /api/subThreads

Response:

    {
     "_id": "5e93e3698f5c4726a7bc135e",
     "title": "SubThread3"
    },
    {
      "_id": "5e93e3698f5c4726a7bc135f",
      "title": "SubThread2"
    }

Status codes:

200 OK: Occurs when all subThreads have been found and returned in the response

500 Internal Server Error: Occurs when the request was unsuccessful

New subThread

Endpoint: /api/subThreads
Method : POST
Purpose : Use this API to transmit a new subThreads to the server.

Send parameters:

Parameter Name Format Purpose
title String The title of the post

Return parameters:

Parameter Name Format Purpose
subThreads._id String The subThread id
subThreads.title String The subThread title
subThreads.date_created String of ISO time The local time of the user when this subThread was created
message (optional) String Contains error message (if applicable)

Example:
POST /api/posts

Body:

{
  "title": "New subThread",
}

Response:

{
    "posts": [],
    "_id": "5ea829de1ae3054390960647",
    "title": "New subThread via POSTMAN",
    "date_created": "2020-04-27T13:04:30.975Z",
    "updatedAt": "2020-04-27T13:04:30.975Z",
    "__v": 0
}

Status codes:

201 Created: Occurs when the new post is successfully created and saved to MongoDB

400 Bad Request: Occurs when request is missing information

Users

Get User Details

Endpoint: /api/users/{id}
Method : GET
Purpose : Use this API to load all the details and activity of the user stored on the server.

Return Parameters:

Parameter Name Format Purpose
users._id String The user's id
users.name String The user's title
users.post String The id's of posts the user has created
user.comments String The id's of comments the user has created
users.upvotes_clap Number The id's of clap upvotes the user has
users.upvotes_laugh Number The id's of laugh upvotes the user has
users.upvotes_sad Number The id's of sad upvotes the user has
message (optional) String Contains error message (if applicable)

Example:
GET /api/users/5ea447fb7728645a4421240f

Response:

{
    "votes": {
        "claps": [
            "5ea4502d7728645a44212415"
        ],
        "laughs": [
            "5ea447fb7728645a44212410",
            "5ea4502d7728645a44212415"
        ],
        "sads": []
    },
    "name": "Ahmad",
    "posts": [
        "5ea447fb7728645a44212410",
        "5ea4502d7728645a44212415",
        "5ea452a27728645a44212417",
        "5ea66e8b62e1931430026ccb",
        "5ea670b762e1931430026cd0",
        "5ea670d762e1931430026cd1"
    ],
    "comments": [
        "5ea448557728645a44212411",
        "5ea448687728645a44212412",
        "5ea44a207728645a44212413",
        "5ea44a397728645a44212414",
        "5ea66ea262e1931430026ccc",
        "5ea66ef862e1931430026ccd",
        "5ea66f0762e1931430026cce",
        "5ea7bb80ddef600968862ef9",
        "5ea7bbc1ddef600968862efa",
        "5ea7bbe3ddef600968862efb"
    ],
    "_id": "5ea447fb7728645a4421240f",
    "email": "auma020@aucklanduni.ac.nz",
    "__v": 0
}

Status codes:

200 OK: Occurs when all posts have been found and returned in the response

400 Bad Request: Occurs when requested request is invalid

404 Not Found: Occurs when requested user does not exist

New User

Endpoint: /api/users
Method : POST
Purpose : Use this API to transmit a new user to the server.

Send parameters:

Parameter Name Format Purpose
email String The email of the users.

Return parameters:

Parameter Name Format Purpose
users._id String The user's id
users.name String The user's title
users.post String The id's of posts the user has created
user.comments String The id's of comments the user has created
users.upvotes_clap Number The id's of clap upvotes the user has
users.upvotes_laugh Number The id's of laugh upvotes the user has
users.upvotes_sad Number The id's of sad upvotes the user has
message (optional) String Contains error message (if applicable)

Example:
POST /api/users

Body:

{
  "email": "....."
}

Response:

{
    "votes": {
        "claps": [],
        "laughs": [],
        "sads": []
    },
    "name": "",
    "posts": [],
    "comments": [],
    "_id": "5ea82d8b1ae3054390960648",
    "email": "abc123@aucklanduni.ac.nz",
    "__v": 0
}

Status codes:

201 Created: Occurs when the new comment is successfully created and saved to MongoDB

400 Bad Request: Occurs when request is missing information

Clone this wiki locally