Assessments and Quizzes

Authentication and Authorization

  1. User Authentication: All requests are authenticated using Clerk's authentication middleware.
  2. Authorization: Only the course owner (instructor) can perform actions on the course, chapters, and questions. Unauthorized users receive a 401 status response.

Functionalities

1. Creating a New Question

  • 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.

2. Updating Question Order

  • 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.

3. Deleting a Question

  • 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.

4. Updating Question

  • 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.

5. Unpublishing a Question

  • 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.

6. Publishing a Question

  • 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.

7. Creating an Answer Option

  • 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.

8. Deleting an Answer Option

  • 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.

Database Tables

Course Table

FieldTypeDescription
idStringPrimary key
userIdStringID of the course owner
titleStringTitle of the course
descriptionStringDescription of the course
imageUrlStringURL of the course image
priceFloatPrice of the course
isPublishedBooleanPublication status
pointsIntPoints for the course
categoryIdStringCategory ID
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp

Chapter Table

FieldTypeDescription
idStringPrimary key
titleStringTitle of the chapter
descriptionStringDescription of the chapter
videoUrlStringURL of the chapter video
positionIntPosition of the chapter
isPublishedBooleanPublication status
courseIdStringCourse ID
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp

Question Table

FieldTypeDescription
idStringPrimary key
titleStringTitle of the question
chapterIdStringChapter ID
positionIntPosition of the question
correctAnswerIndexIntIndex of the correct answer
isPublishedBooleanPublication status
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp

Answer Option Table

FieldTypeDescription
idStringPrimary key
textStringText of the answer option
questionIdStringQuestion ID
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp

Flow Diagrams

Combined Flow Diagram

+-------------------------+
| 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                |
+-------------------------+

Detailed Flow for Managing Questions

+-------------------------+
| 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 |
+-------------------------+

Detailed Flow for Managing Answer Options

+-------------------------+
| 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       |
+-------------------------+