Add Course Rating
User API
Add Course Rating
Submit a rating and review for a completed course
POST
Add Course Rating
Overview
Allows students to rate a course they have completed. Ratings are stored with the user’s enrollment record and displayed on course detail pages.Authentication
Requires Clerk authentication. The user must be enrolled in the course.Request Body
The MongoDB ObjectId of the course to rate
Rating value between 1-5 starsMust be an integer: 1, 2, 3, 4, or 5
Optional text review/comment about the courseMaximum length: 500 characters
Response
Indicates whether the rating was saved successfully
Confirmation message
The updated course rating information
Request Example
Response Example
Error Responses
400 Bad Request
- Missing required fields
- Invalid rating value (not 1-5)
- Review text exceeds 500 characters
404 Not Found
- User is not enrolled in the course
- Course does not exist
403 Forbidden
- User has not completed the course yet
- Ratings may be restricted to completed courses only
Implementation Details
Rating Storage
Ratings are stored in theUser model’s courseRatings array:
Rating Update Rules
- Users can update their rating for a course by submitting again
- The most recent rating replaces any previous rating
- Average rating is recalculated for the course after each submission
Code Examples
Use Cases
- Collect student feedback on course quality
- Display ratings on course pages to help prospective students
- Calculate average ratings to rank courses
- Identify top-rated courses for marketing purposes
Related Endpoints
- Get Course - View course with ratings
- Get Enrolled Courses - See which courses you can rate