curl --request POST \
--url https://api.example.com/api/user/add-rating \
--header 'Content-Type: application/json' \
--data '
{
"courseId": "<string>",
"rating": 123,
"review": "<string>"
}
'{
"success": true,
"message": "<string>",
"data": {
"courseId": "<string>",
"rating": 123,
"review": "<string>",
"averageRating": 123,
"totalRatings": 123
}
}Submit a rating and review for a completed course
curl --request POST \
--url https://api.example.com/api/user/add-rating \
--header 'Content-Type: application/json' \
--data '
{
"courseId": "<string>",
"rating": 123,
"review": "<string>"
}
'{
"success": true,
"message": "<string>",
"data": {
"courseId": "<string>",
"rating": 123,
"review": "<string>",
"averageRating": 123,
"totalRatings": 123
}
}{
"courseId": "65f3a1b2c3d4e5f6g7h8i9j0",
"rating": 5,
"review": "Excellent course! The instructor explained complex concepts clearly and the hands-on projects were very helpful."
}
{
"success": true,
"message": "Rating submitted successfully",
"data": {
"courseId": "65f3a1b2c3d4e5f6g7h8i9j0",
"rating": 5,
"review": "Excellent course! The instructor explained...",
"averageRating": 4.7,
"totalRatings": 128
}
}
User model’s courseRatings array:
courseRatings: [
{
courseId: ObjectId,
rating: Number, // 1-5
review: String,
createdAt: Date
}
]
const response = await fetch(`${BACKEND_URL}/api/user/add-rating`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${clerkToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
courseId: '65f3a1b2c3d4e5f6g7h8i9j0',
rating: 5,
review: 'Great course with excellent content!'
})
});
const data = await response.json();
console.log(`Average rating: ${data.data.averageRating}`);