Comments

This page will go into detail on the properties of the comment class as well as the different endpoints used to query, create, update, and delete comments. Comments can be made by anyone on posts made in groups or courses.

The comment model

This model details all of the properties of an comment as well as their references.

Properties

  • Name
    id
    Type
    string
    Description

    Unique identifier for the comment.

  • Name
    post_id
    Type
    string
    Description

    Unique identifier for the post the comment is made on.

  • Name
    author_id
    Type
    string
    Description

    Unique identifier for the author of the comment.

  • Name
    content
    Type
    string
    Description

    Text content of the comment.

  • Name
    likes
    Type
    string[]
    Description

    Array of user ids that have liked this comment

  • Name
    images
    Type
    string
    Description

    File path for an image from the supabase storage.

  • Name
    created_at
    Type
    timestamp
    Description

    Timestamp of when the comment was created. Generated automatically at creation in ISO 8601 format.


POST/v1/comments/create

Create a comment

This endpoint allows you to add a new comment to the database.

Required parameters

  • Name
    post_id
    Type
    string
    Description

    Unique identifier for the post the comment is made on.

  • Name
    author_id
    Type
    string
    Description

    Unique identifier for the author of the comment.

Optional parameters

  • Name
    id
    Type
    string
    Description

    Unique identifier for the comment.

  • Name
    content
    Type
    string
    Description

    Text content of the comment.

  • Name
    likes
    Type
    string[]
    Description

    Array of user ids that have liked this comment

  • Name
    images
    Type
    string
    Description

    File path for an image from the supabase storage.

  • Name
    created_at
    Type
    timestamp
    Description

    Timestamp of when the comment was created. Generated automatically at creation in ISO 8601 format.

Request

POST
/v1/comments/create
import ApiClient from '@example/protocol-api'

const client = new ApiClient(token)

await client.comment.createComment({
  post_id: "33c1a341-e6c7-48b4-ad94-831273a8faf3",
  author_id: "627a64c9-645a-491f-a851-b59331248af7",
  content: "Very cool"
})

Response

{
  "id": "fd928c79-f608-4693-992a-543416306a27",
  "post_id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
  "author_id": "627a64c9-645a-491f-a851-b59331248af7",
  "content": "Very cool",
  "likes": [],
  "images": null,
  "created_at": "2024-07-04T14:15:57.375619+00:00"
}

GET/v1/comments/:id

Retrieve a comment

This endpoint allows you to retrieve a comment by providing their id. Refer to the list at the top of this page to see which properties are included with comment objects.

Request

GET
/v1/comments/fd928c79-f608-4693-992a-543416306a27
import ApiClient from '@example/protocol-api'

const client = new ApiClient(token)

await client.comment.getComment('5c44a3a4-3fb3-4f14-9eb8-eb716a807922')

Response

{
  "id": "fd928c79-f608-4693-992a-543416306a27",
  "post_id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
  "author_id": "627a64c9-645a-491f-a851-b59331248af7",
  "content": "Very cool",
  "likes": [],
  "images": null,
  "created_at": "2024-07-04T14:15:57.375619+00:00"
}

GET/v1/comments/post/:id

Retrieve all comments for a post

This endpoint allows you to retrieve all comments for a post given the post id.

Request

GET
/v1/comments/posts/33c1a341-e6c7-48b4-ad94-831273a8faf3
import ApiClient from '@example/protocol-api'

const client = new ApiClient(token)

await client.comment.getAllPostComments('33c1a341-e6c7-48b4-ad94-831273a8faf3')

Response

[
  {
    "id": "fd928c79-f608-4693-992a-543416306a27",
    "post_id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
    "author_id": "627a64c9-645a-491f-a851-b59331248af7",
    "content": "Very cool",
    "likes": [],
    "images": null,
    "created_at": "2024-07-04T14:15:57.375619+00:00"
  },
  {
    "id": "1aba9ef6-2155-413c-994e-3f6e9d127da4",
    "post_id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
    "author_id": "73b0470e-29bf-4da4-98a1-64f97bb0960b",
    "content": "Thanks!",
    "likes": [],
    "images": null,
    "created_at": "2024-07-04T15:26:50.375619+00:00"
  }
]

PATCH/v1/comments/update/:id

Update a comment

This endpoint allows you to perform an update on a comment. The id, post_id, author_id, and created_at properties can't be changed. It is suggested to use a different endpoint to update likes.

Optional parameters

  • Name
    content
    Type
    string
    Description

    Text content of the comment.

  • Name
    likes
    Type
    string[]
    Description

    Array of user ids that have liked this comment

  • Name
    images
    Type
    string
    Description

    File path for an image from the supabase storage.

Request

PATCH
/v1/comments/update/fd928c79-f608-4693-992a-543416306a27
import ApiClient from '@example/protocol-api'

const client = new ApiClient(token)

await client.comments.updateComment('fd928c79-f608-4693-992a-543416306a27', {
    images: 'image path',
})

Response

{
  "id": "fd928c79-f608-4693-992a-543416306a27",
  "post_id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
  "author_id": "627a64c9-645a-491f-a851-b59331248af7",
  "content": "Very cool",
  "likes": [],
  "images": "image path",
  "created_at": "2024-07-04T14:15:57.375619+00:00"
}

PATCH/v1/comments/update-likes/:id/:userId?unlike=value

Update likes on a comment

This endpoint allows you to like or unlike a post given the comment id and user id that is liking the post. The user must have liked the post before they're able to unlike it. Uses a query parameter for the unlike value, which is true if you want to unlike a comment.

Request

PATCH
/v1/comments/update-likes/fd928c79-f608-4693-992a-543416306a27/37035d44-67c7-4faf-8aac-a91a02e65614?unlike=false
import ApiClient from '@example/protocol-api'

const client = new ApiClient(token)

await client.posts.updateLikes("fd928c79-f608-4693-992a-543416306a27", "37035d44-67c7-4faf-8aac-a91a02e65614", false)
  {
    "status": 204
  }

DELETE/v1/comments/delete/:id

Delete an comment

This endpoint allows you to delete a specified comment using their id.

Request

DELETE
/v1/comments/delete/1aba9ef6-2155-413c-994e-3f6e9d127da4
import ApiClient from '@example/protocol-api'

const client = new ApiClient(token)

await client.comment.deleteComment('1aba9ef6-2155-413c-994e-3f6e9d127da4')

Was this page helpful?