User Authentication : All requests are authenticated using Clerk's authentication middleware.
Authorization : Only the course owner (instructor) can perform actions on the course, chapters, and questions. Unauthorized users receive a 401 status response.
Request : POST /courses/:courseId/chapters/:chapterId/questions
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
Body : JSON containing title and correctAnswerIndex.
Process :
Authenticate the user.
Verify the user is the course owner.
Determine the position for the new question.
Create the new question in the database.
Response : The created question in JSON format.
Request : PUT /courses/:courseId/chapters/:chapterId/questions
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
Body : JSON containing a list of questions with their new positions.
Process :
Authenticate the user.
Verify the user is the course owner.
Update the positions of the questions in the database.
Response : A success message.
Request : DELETE /courses/:courseId/chapters/:chapterId/questions/:questionId
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
questionId: The ID of the question.
Process :
Authenticate the user.
Verify the user is the course owner.
Delete the question from the database.
If there are no published questions in the chapter, update the chapter's status to unpublished.
Response : The deleted question in JSON format.
Request : PATCH /courses/:courseId/chapters/:chapterId/questions/:questionId
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
questionId: The ID of the question.
Body : JSON containing title, correctAnswerIndex, and other question details.
Process :
Authenticate the user.
Verify the user is the course owner.
Update the question in the database.
Response : The updated question in JSON format.
Request : PATCH /courses/:courseId/chapters/:chapterId/questions/:questionId/unpublish
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
questionId: The ID of the question.
Process :
Authenticate the user.
Verify the user is the course owner.
Update the question's status to unpublished.
If there are no published questions in the chapter, update the chapter's status to unpublished.
Response : The unpublished question in JSON format.
Request : PATCH /courses/:courseId/chapters/:chapterId/questions/:questionId/publish
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
questionId: The ID of the question.
Process :
Authenticate the user.
Verify the user is the course owner.
Validate required fields.
Update the question's status to published.
Response : The published question in JSON format.
Request : POST /courses/:courseId/chapters/:chapterId/questions/:questionId/answer-options
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
questionId: The ID of the question.
Body : JSON containing text.
Process :
Authenticate the user.
Verify the user is the course owner.
Create the answer option in the database.
Response : The created answer option in JSON format.
Request : DELETE /courses/:courseId/chapters/:chapterId/questions/:questionId/answer-options/:answerOptionId
Parameters :
courseId: The ID of the course.
chapterId: The ID of the chapter.
questionId: The ID of the question.
answerOptionId: The ID of the answer option.
Process :
Authenticate the user.
Verify the user is the course owner.
Delete the answer option from the database.
Response : The deleted answer option in JSON format.
Field Type Description
id String Primary key
userId String ID of the course owner
title String Title of the course
description String Description of the course
imageUrl String URL of the course image
price Float Price of the course
isPublished Boolean Publication status
points Int Points for the course
categoryId String Category ID
createdAt DateTime Creation timestamp
updatedAt DateTime Last update timestamp
Field Type Description
id String Primary key
title String Title of the chapter
description String Description of the chapter
videoUrl String URL of the chapter video
position Int Position of the chapter
isPublished Boolean Publication status
courseId String Course ID
createdAt DateTime Creation timestamp
updatedAt DateTime Last update timestamp
Field Type Description
id String Primary key
title String Title of the question
chapterId String Chapter ID
position Int Position of the question
correctAnswerIndex Int Index of the correct answer
isPublished Boolean Publication status
createdAt DateTime Creation timestamp
updatedAt DateTime Last update timestamp
Field Type Description
id String Primary key
text String Text of the answer option
questionId String Question ID
createdAt DateTime Creation timestamp
updatedAt DateTime Last update timestamp
+-------------------------+
| User Authenticates |
+-------------------------+
|
v
+-------------------------+
| Verify User Role |
+-------------------------+
|
v
+-------------------------+
| Is Course Owner? |
+---------+---------------+
| Yes
v
+-------------------------+
| Manage Questions |
| - Create |
| - Update |
| - Delete |
| - Publish/Unpublish |
+---------+---------------+
|
v
+-------------------------+
| Manage Answer Options |
| - Create |
| - Delete |
+-------------------------+
+-------------------------+
| Authenticate User |
+-------------------------+
|
v
+-------------------------+
| Verify User is Owner |
+-------------------------+
|
v
+-------------------------+
| Action: Create |
+-------------------------+
| 1. Validate Input |
| 2. Determine Position |
| 3. Insert into DB |
+-------------------------+
|
v
+-------------------------+
| Action: Update |
+-------------------------+
| 1. Validate Input |
| 2. Update DB Record |
+-------------------------+
|
v
+-------------------------+
| Action: Delete |
+-------------------------+
| 1. Validate Ownership |
| 2. Delete from DB |
| 3. Check Chapter Status |
+-------------------------+
+-------------------------+
| Authenticate User |
+-------------------------+
|
v
+-------------------------+
| Verify User
is Owner |
+-------------------------+
|
v
+-------------------------+
| Action: Create |
+-------------------------+
| 1. Validate Input |
| 2. Insert into DB |
+-------------------------+
|
v
+-------------------------+
| Action: Delete |
+-------------------------+
| 1. Validate Ownership |
| 2. Delete from DB |
+-------------------------+