Skip to content

API docs

George edited this page Dec 12, 2022 · 23 revisions

API Documentation

FEATURE 0: USER AUTHORIZATION

All endpoints that require authentication

All endpoints that require a current user to be logged in.

  • Request: endpoints that require authentication

  • Error Response: Require authentication

    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Authentication required",
          "statusCode": 401
      }

All endpoints that require proper authorization

All endpoints that require authentication and the current user does not have the correct role(s) or permission(s).

  • Request: endpoints that require proper authorization

  • Error Response: Require proper authorization

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Forbidden",
          "statusCode": 403
      }

Get the Current User

Returns the information about the current user that is logged in.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/users/session
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "first_name": "John",
          "last_name": "Smith",
          "username": "JohnSmith",
          "email": "john.smith@gmail.com",
          "biography": "I'm really cool",
          "hashed_password": "",
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36"
          "preview_image": "url"
      }

Get the User details by user id

Returns the information about a user.

  • Require Authentication: False

  • Request

    • Method: GET
    • URL: /api/users/:userid
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "first_name": "John",
          "last_name": "Smith",
          "username": "JohnSmith",
          "email": "john.smith@gmail.com",
          "biography": "I'm really cool",
          "preview_image": "url"
      }

Log In a User

Logs in a valid user with valid credentials and returns the session user information.

  • Require Authentication: false

  • Request

    • Method: POST

    • URL: /api/users/login

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "credential": "john.smith@gmail.com",
          "password": "secret password"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "first_name": "John",
          "last_name": "Smith",
          "username": "JohnSmith",
          "email": "john.smith@gmail.com",
          "biography": "I'm really cool",
          "preview_image": "url"
      }
  • Error Response: Invalid credentials

    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Invalid credential",
          "statusCode": 401
      }
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation error",
          "statusCode": 401,
          "errors": {
              "credential": "Email or username is required",
              "password": "Password is required"
          }
      }

Sign Up a User

Creates a new user, logs them in as the session user, and returns the session user's information.

  • Require Authentication: false

  • Request

    • Method: POST

    • URL: /api/signup

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "first_name": "John",
          "last_name": "Smith",
          "username": "JohnSmith",
          "email": "john.smith@gmail.com",
          "biography": "I'm really cool",
          "preview_image": "url"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "first_name": "John",
          "last_name": "Smith",
          "username": "JohnSmith",
          "email": "john.smith@gmail.com",
          "biography": "I'm really cool",
          "preview_image": "url"
      }
  • Error response: User already exists with the specified email

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "User already exists",
          "statusCode": 403,
          "errors": {
              "email": "User with that email already exists"
          }
      }
  • Error response: User already exists with the specified profile name

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "User already exists",
          "statusCode": 403,
          "errors": {
              "username": "User with that username already exists"
          }
      }
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation error",
          "statusCode": 400,
          "errors": {
              "email": "Invalid email",
              "username": "Username is required",
              "first_name": "First Name is required",
              "last_name": "Last Name is required"
          }
      }

FEATURE 1: POSTS FEATURE

Get all Posts by User id

Returns all the posts from a user.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/users/:userid/posts
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Posts": [
              {
                   "id": 2,
                   "userId": 2,
                   "caption": "caption 2",
                   "location": "Dominican Republic",
                   "likes": 2,
                   "comments": 2,
                   "likeStatus": true,
                   "created_at": "2021-11-19 20:39:36",
                   "updated_at": "2021-11-19 20:39:36",
                   "Likes": [
                       {
                          "id": 1,
                          "user_id": 2,
                          "post_id": 2,
                          "like_status": true,
                          "created_at": "2021-11-19 20:39:36",
                          "updated_at": "2021-11-19 20:39:36"
                       }
                   ],
                   "Media": [
                       {
                           "id": 1,
                           "user_id": 2,
                           "media_file": "test",
                           "type": "image"
                       }
                   ],
                   "Owner": {
                       "id": 2,
                       "username": "John",
                       "previewImage": "url"
                   }
              },
          ]
      }

Get all Posts created by the Current User

Returns all the posts created by the current user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/users/current/posts
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Posts": [
              {
                  "id": 2,
                  "userId": 2,
                  "caption": "caption 2",
                  "location": "Dominican Republic",
                  "likes": 2,
                  "comments": 2,
                  "likeStatus": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36",
                  "Likes": [
                      {
                          "id": 1,
                          "user_id": 2,
                          "post_id": 2,
                          "like_status": true,
                          "created_at": "2021-11-19 20:39:36",
                          "updated_at": "2021-11-19 20:39:36"
                      }
                  ],
                  "Media": [
                     {
                         "id": 1,
                         "user_id": 2,
                         "media_file": "test",
                         "type": "image"
                     }
                  ],
                  "Owner": {
                      "id": 2,
                      "username": "John",
                      "previewImage": "url"
                  }
              },
          ]
      }

Get all Posts of Users Followed by Current User

Returns all the posts of the users that the current user follows.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/users/current/following/posts
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Posts": [
              {
                  "id": 2,
                  "userId": 2,
                  "caption": "caption 2",
                  "location": "Dominican Republic",
                  "likes": 2,
                  "comments": 2,
                  "likeStatus": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36",
                  "Likes": [
                      {
                          "id": 1,
                          "user_id": 2,
                          "post_id": 2,
                          "like_status": true,
                          "created_at": "2021-11-19 20:39:36",
                          "updated_at": "2021-11-19 20:39:36"
                      }
                  ],
                  "Media": [
                      {
                          "id": 1,
                          "user_id": 2,
                          "media_file": "test",
                          "type": "image"
                      }
                  ],
                  "Owner": {
                      "id": 2,
                      "username": "John",
                      "previewImage": "url"
                  }
              },        
          ]
      }

Get details of a Post from an Id

Returns the details of a post specified by its id.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/posts/:postId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "userId": 2,
          "caption": "caption 2",
          "location": "Dominican Republic",
          "likes": 2,
          "comments": 2,
          "likeStatus": true,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          "Likes": [
              {
                  "id": 1,
                  "user_id": 2,
                  "post_id": 2,
                  "like_status": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36"
              }
          ],
          "Media": [
              {
                  "id": 1,
                  "user_id": 2,
                  "media_file": "test",
                  "type": "image"
              }
          ],
          "Owner": {
              "id": 2,
              "username": "John",
              "previewImage": "url"
          }
      }        
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Post couldn't be found",
        "statusCode": 404
      }

Create a Post

Creates and returns a new post.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/posts

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "caption": "Time",
          "location": "New York City"
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "userId": 2,
          "caption": "caption 2",
          "location": "Dominican Republic",
          "likes": 0,
          "comments": 0,
          "likeStatus": false,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          "Likes" : [{}],
          "Media" : [
              {
                  "id": 1,
                  "user_id": 2,
                  "media_file": "test",
                  "type": "image"
              }
          ],
          "Owner": {
              "id": 2,
              "username": "John",
              "previewImage": "url"
          }
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation Error",
          "statusCode": 400,
          "errors": {
             "caption": "Caption is required",
             "location": "Location is required"
          }
      }

Edit a Post

Updates and returns an existing post.

  • Require Authentication: true

  • Require proper authorization: Post must belong to the current user

  • Request

    • Method: PUT

    • URL: /api/posts/:postId

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "caption": "Yesterday",
          "location": "San Francisco"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "userId": 2,
          "caption": "caption 2",
          "location": "Dominican Republic",
          "likes": 2,
          "comments": 2,
          "likeStatus": true,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          "Likes": [
              {
                  "id": 1,
                  "user_id": 2,
                  "post_id": 2,
                  "like_status": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36"
              }
          ],
          "Media": [
              {
                  "id": 1,
                  "user_id": 2,
                  "media_file": "test",
                  "type": "image"
              }
          ],
          "Owner": {
              "id": 2,
              "username": "John",
              "previewImage": "url"
          }
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation Error",
          "statusCode": 400,
          "errors": {
              "caption": "Caption is required",
              "location": "Location is required"
          }
      }
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Post couldn't be found",
          "statusCode": 404
      }

Delete a Post

Deletes an existing post.

  • Require Authentication: true

  • Require proper authorization: Post must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/posts/:postId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Successfully deleted",
          "statusCode": 200
      }
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Post couldn't be found",
          "statusCode": 404
      }

FEATURE 2: COMMENTS FEATURE

Get all Comments by a Post's id

Returns all the comments that belong to a post specified by id.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/posts/:postId/comments
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Comments": [
              {
                  "id": 2,
                  "user_id": 2,
                  "comment": "comment 1",
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36",
                  "numOfReplies": 2,
                  "Owner": {
                      "id": 2,
                      "username": "John",
                      "preview_image": "url"
                  }
              },
          ]
      }
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Post not found",
          "statusCode": 404
      }

Create a Comment for a Post based on the Post's id

Create and return a new comment for a post specified by id.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/posts/:postId/comments

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "comment": "I love this post!"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "user_id": 2,
          "comment": "comment 1",
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          "numOfReplies": 0,
          "Owner": {
              "id": 2,
              "username": "John",
              "preview_image": "url"
          }
      }
  • Error Response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation error",
          "statusCode": 400,
          "errors": {
              "body": "Comment body text is required"
          }
      }
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Post not found",
          "statusCode": 404
      }

Edit a Comment

Update and return an existing comment.

  • Require Authentication: true

  • Require proper authorization: Comment must belong to the current user

  • Request

    • Method: PUT

    • URL: /api/comments/:commentId

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "comment": "I love this post!"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "user_id": 2,
          "comment": "comment 1",
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
          "numOfReplies": 2,
          "Owner": {
              "id": 2,
              "username": "John",
              "preview_image": "url"
          }
      }
  • Error Response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation error",
          "statusCode": 400,
          "errors": {
              "body": "Comment body text is required"
          }
      }
  • Error response: Couldn't find a Comment with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Comment couldn't be found",
          "statusCode": 404
      }

Delete a Comment

Delete an existing comment.

  • Require Authentication: true

  • Require proper authorization: Comment must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/comments/:commentId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Successfully deleted",
          "statusCode": 200
      }
  • Error response: Couldn't find a Comment with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Comment couldn't be found",
          "statusCode": 404
      }

FEATURE 3: FOLLOWERS FEATURE

Get all Followers from a user id

Returns all Followers for that user

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/users/:userId/followers
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Followers": [
              {
                  "id": 2,
                  "user_id": 2,
                  "follows_user_id": 3,
                  "following_status": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36"
                  "Owner": {
                      "id": 2,
                      "first_name": "John",
                      "last_name": "Smith",
                      "username": "jsmith",
                      "preview_image": "url"
                  }
              },
          ]
      }
  • Error response: Couldn't find a user with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "User couldn't be found",
        "statusCode": 404
      }

Get all Following of a User from a user id

Returns all the user following the specified user.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/users/:userId/followers
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Following": [
              {
                  "id": 2,
                  "user_id": 2,
                  "follows_user_id": 3,
                  "following_status": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36"
                  "Owner": {
                      "id": 2,
                      "first_name": "John",
                      "last_name": "Smith",
                      "username": "jsmith",
                      "preview_image": "url"
                  }
              },
          ]
      }
  • Error response: Couldn't find a User with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "User couldn't be found",
        "statusCode": 404
      }

Get all follow suggestions of a User from a user id

Returns all the follower suggestions for the specified user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/users/:userId/following/suggestions
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Followers Suggestion": [
              {
                  "id": 2,
                  "user_id": 2,
                  "follows_user_id": 3,
                  "following_status": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36"      
              }
          ]
      }
  • Error response: Couldn't find a User with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "User couldn't be found",
          "statusCode": 404
      }

Follow a User based on the User's id

Follow a user specified by id.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/users/:userId/followers

    • Body:

      {
          "follows_user_id": 1
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "user_id": 2,
          "follows_user_id": 3,
          "following_status": true,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36" 
      }
  • Error response: Couldn't find a User with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "User couldn't be found",
          "statusCode": 404
      }
  • Error response: Current User is already a follower of the user

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Current user is already a follower of the user",
          "statusCode": 400
      }

Unfollow a User based on the User's id

Change the status of a follower of a user specified by id.

  • Require Authentication: true

  • Require proper Authorization: Current user must be the follower of the user

  • Request

    • Method: PUT

    • URL: /api/users/:userId/followers

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "follows_user_id": 2
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "user_id": 2,
          "follows_user_id": 3,
          "following_status": true,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36" 
      }
  • Error response: Couldn't find a User with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "User couldn't be found",
          "statusCode": 404
      }
  • Error response: If changing the status and Current User is not the follower.

    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Current user must be the follower to unfollow the user",
          "statusCode": 403
      }
  • Error response: If user is not a follower

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Current user is not a follower of the user",
          "statusCode": 404
      }

FEATURE 4: MEDIA FEATURE

Add Media to a Post based on the Post's id

Create and return new media for a post specified by id.

  • Require Authentication: true

  • Require proper authorization: Post must belong to the current user

  • Request

    • Method: POST

    • URL: /api/posts/:postId/media

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "media_file": "url",
          "type": "image"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 2,
          "user_id": 2,
          "post_id": 2,
          "media_file": "url",
          "type": "image",
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36"
      }
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Post couldn't be found",
          "statusCode": 404
      }

Delete Media

Deletes existing media.

  • Require Authentication: true

  • Require proper authorization: Media must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/media/:mediaId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Successfully deleted",
          "statusCode": 200
      }
  • Error response: Couldn't find Media with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Media couldn't be found",
          "statusCode": 404
      }

FEATURE 5: LIKES FEATURE

Get all likes by post Id

Returns all likes for that post

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/posts/:postId/likes
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Likes": [
              {
                  "id": 2,
                  "user_Id": 2,
                  "post_id": 2,
                  "like_status": true,
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36",
                  "Owner": {
                      "id": 2,
                      "username": "John",
                      "first_name": "John",
                      "last_name": "Smith",
                      "previewImage": "url"
                  }
              },
          ]
      }
  • Error response: Couldn't find a post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Post couldn't be found",
          "statusCode": 404
      }

Add Likes to a Post based on the Post's id

Create and return new likes for a post specified by id.

  • Require Authentication: true

  • Request

    • Method: POST
    • URL: /api/posts/:postId/likes
    • Headers:
      • Content-Type: application/json
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "user_id": 1,
          "post_id": 1,
          "like_status": true,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36"
      }
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Post couldn't be found",
          "statusCode": 404
      }

Unlike

Updates and returns an existing like.

  • Require Authentication: true

  • Require proper authorization: Like must belong to the current user

  • Request

    • Method: PUT

    • URL: /api/likes/:likeId

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "like_status": false
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "user_id": 1,
          "post_id": 1,
          "like_status": false,
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-20 20:00:00"
      }
  • Error response: Couldn't find a Post with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Like couldn't be found",
          "statusCode": 404
      }

FEATURE 6: REPLIES

Get all replies under the comment

Returns all the replies under the comment.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/comments/:commentid/replies
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "Replies": [
              {
                  "id": 1,
                  "comment_id": 1,
                  "user_id":1,
                  "reply": "@Abc thank you for your comments"
                  "created_at": "2021-11-19 20:39:36",
                  "updated_at": "2021-11-19 20:39:36",
                  "Owner": {
                      "id": 1,
                      "username": "JohnSmith",
                      "preview_image": "image url"
                  }
              },
          ]
      }

Create a Reply under the comment

Creates and returns a new reply.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/comments/:commentid/replies

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "reply": "@Abc thank you for your comments",
      }
  • Successful Response

    • Status Code: 201

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "comment_id": 1,
          "user_id":1,
          "reply": "@Abc thank you for your comments"
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-19 20:39:36",
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation Error",
          "statusCode": 400,
          "errors": {
              "reply": "reply is required",
          }
      }

Edit a reply

Updates and returns an existing reply.

  • Require Authentication: true

  • Require proper authorization: Reply must belong to the current user

  • Request

    • Method: PUT

    • URL: /api/replies/:replyid

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "reply": "@Abc I love your comment"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "id": 1,
          "user_id": 1,
          "comment_id": 1,
          "reply": "@Abc I love your comment"
          "created_at": "2021-11-19 20:39:36",
          "updated_at": "2021-11-20 20:40:40"
      }
  • Error Response: Body validation error

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Validation Error",
          "statusCode": 400,
          "errors": {
              "reply": "reply is required",
          }
      }
  • Error response: Couldn't find a reply with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Reply couldn't be found",
          "statusCode": 404
      }

Delete a reply

Deletes an existing reply.

  • Require Authentication: true

  • Require proper authorization: Reply must belong to the current user

  • Request

    • Method: DELETE
    • URL: /api/replies/:replyid
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Successfully deleted",
          "statusCode": 200
      }
  • Error response: Couldn't find a reply with the specified id

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "message": "Reply couldn't be found",
          "statusCode": 404
      }