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.
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
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"
}
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
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"
}
Retrieve all comments for a post
This endpoint allows you to retrieve all comments for a post given the post id.
Request
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"
}
]
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
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"
}
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
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 an comment
This endpoint allows you to delete a specified comment using their id.
Request
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.comment.deleteComment('1aba9ef6-2155-413c-994e-3f6e9d127da4')