Posts
This page will go into detail on the properties of the post class as well as the different endpoints used to query, create, update, and delete posts. All users can create posts to convey a message to a group or course.
The post model
This model details all of the properties of an post as well as their references.
Properties
- Name
id
- Type
- string
- Description
Unique identifier for the post. Generated randomly by default.
- Name
author_id
- Type
- string
- Description
Unique identifier for creator of the post.
- Name
course_id
- Type
- string
- Description
Unique identifier for the course the post will be made in, if a post has a course id it can't have a group id.
- Name
group_id
- Type
- string
- Description
Unique identifier for the group the post will be made in, if a post has a group id it can't have a course id.
- Name
tags
- Type
- object
- Description
Object containing all tags the post has. Stored with the tag name as the key and a color as the value. Can have none by default.
- Name
title
- Type
- string
- Description
Title of the post.
- Name
content
- Type
- string
- Description
Text content a post contains.
- Name
likes
- Type
- string[]
- Description
array containing user ids that have like the post.
- Name
images
- Type
- string
- Description
file path to imiage in supabase storage.
- Name
created_at
- Type
- timestamp
- Description
Timestamp of when the post was created. Generated automatically at creation in ISO 8601 format.
Create a post
This endpoint allows you to add a new post to the database.
Required parameters
- Name
author_id
- Type
- string
- Description
Unique identifier for creator of the post.
- Name
course_id
- Type
- string
- Description
Unique identifier for the course the post will be made in, if a post has a course id it can't have a group id.
- Name
group_id
- Type
- string
- Description
Unique identifier for the group the post will be made in, if a post has a group id it can't have a course id.
- Name
title
- Type
- string
- Description
Title of the post.
- Name
content
- Type
- string
- Description
Text content a post contains.
Optional parameters
- Name
id
- Type
- string
- Description
Unique identifier for the post. Generated randomly by default.
- Name
tags
- Type
- object
- Description
Object containing all tags the post has. Stored with the tag name as the key and a color as the value. Can have none by default.
- Name
likes
- Type
- string[]
- Description
array containing user ids that have like the post.
- Name
images
- Type
- string
- Description
file path to imiage in supabase storage.
Request
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.post.createPost({
author_id: "37035d44-67c7-4faf-8aac-a91a02e65614",
course_id: "c8f9040d-03d3-4675-a3cb-f46ea31406b6",
tags: {"Important": "red", "Homework": "green"},
title: "Homework update",
content: "Homework content has been updated, more questions have been assigned",
})
Response
{
"id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
"author_id": "37035d44-67c7-4faf-8aac-a91a02e65614",
"course_id": "c8f9040d-03d3-4675-a3cb-f46ea31406b6",
"group_id": null,
"tags": {"Important": "red", "Homework": "green"},
"title": "Homework update",
"content": "Homework content has been updated, more questions have been assigned",
"likes": [],
"images": null,
"created_at": "2024-07-02T09:37:83.912408+00:00"
}
Retrieve a post
This endpoint allows you to retrieve a post by providing their id. Refer to the list at the top of this page to see which properties are included with post objects.
Request
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.post.getPost('33c1a341-e6c7-48b4-ad94-831273a8faf3')
Response
{
"id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
"author_id": "37035d44-67c7-4faf-8aac-a91a02e65614",
"course_id": "c8f9040d-03d3-4675-a3cb-f46ea31406b6",
"group_id": null,
"tags": {"Important": "red", "Homework": "green"},
"title": "Homework update",
"content": "Homework content has been updated, more questions have been assigned",
"likes": [],
"images": null,
"created_at": "2024-07-02T09:37:83.912408+00:00"
}
Retrieve all posts for a course
This endpoint allows you to retrieve all posts for a course by providing the course id. Returns an array of the posts.
Request
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.post.getAllCoursePosts('c8f9040d-03d3-4675-a3cb-f46ea31406b6')
Response
[
{
"id": "33c1a341-e6c7-48b4-ad94-831273a8faf3",
"author_id": "37035d44-67c7-4faf-8aac-a91a02e65614",
"course_id": "c8f9040d-03d3-4675-a3cb-f46ea31406b6",
"group_id": null,
"tags": {"Important": "red", "Homework": "green"},
"title": "Homework update",
"content": "Homework content has been updated, more questions have been assigned",
"likes": [],
"images": null,
"created_at": "2024-07-02T09:37:83.912408+00:00"
},
{
"id": "0c98f97f-44b8-41b3-867c-866f54ced4e4",
"author_id": "37035d44-67c7-4faf-8aac-a91a02e65614",
"course_id": "c8f9040d-03d3-4675-a3cb-f46ea31406b6",
"group_id": null,
"tags": {"Assignment": "yellow"},
"title": "Assignment 1 error",
"content": "Question 5 has a question that we haven't covered, please don't do it.",
"likes": ["627a64c9-645a-491f-a851-b59331248af7"],
"images": null,
"created_at": "2024-07-05T17:36:33.912408+00:00"
}
]
Update a post
This endpoint allows you to perform an update on a post. The id, author_id, course_id, group_id, and created_at properties can't be changed. It is suggested to update likes using a different endpoint.
Optional parameters
- Name
title
- Type
- string
- Description
Title of the post.
- Name
content
- Type
- string
- Description
Text content a post contains.
- Name
tags
- Type
- object
- Description
Object containing all tags the post has. Stored with the tag name as the key and a color as the value. Can have none by default.
- Name
likes
- Type
- string[]
- Description
array containing user ids that have like the post.
- Name
images
- Type
- string
- Description
file path to imiage in supabase storage.
Request
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.posts.updatePost('0c98f97f-44b8-41b3-867c-866f54ced4e4', {
tags: {"Important": "red", "Assignment": "yellow"}
})
Response
{
"id": "0c98f97f-44b8-41b3-867c-866f54ced4e4",
"author_id": "37035d44-67c7-4faf-8aac-a91a02e65614",
"course_id": "c8f9040d-03d3-4675-a3cb-f46ea31406b6",
"group_id": null,
"tags": {"Important": "red", "Assignment": "yellow"},
"title": "Assignment 1 error",
"content": "Question 5 has a question that we haven't covered, please don't do it.",
"likes": ["627a64c9-645a-491f-a851-b59331248af7"],
"images": null,
"created_at": "2024-07-05T17:36:33.912408+00:00"
}
Update likes on a post
This endpoint allows you to like or unlike a post given the post 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 post.
Request
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.posts.updateLikes("0c98f97f-44b8-41b3-867c-866f54ced4e4", "627a64c9-645a-491f-a851-b59331248af7", true)
{
"status": 204
}
Delete a post
This endpoint allows you to delete a specified post using their id. This will also delete any comments associated with this post.
Request
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.post.deletePost('33c1a341-e6c7-48b4-ad94-831273a8faf3')
Response
{
"status": 204
}