feat(#623): add course rating and review system API#954
Open
jerrymusaga wants to merge 1 commit into
Open
Conversation
- Add course_reviews table (migration 013) with course_id FK, learner_address, rating 1-5, review_text, created_at, and a UNIQUE(course_id, learner_address) constraint to prevent duplicate reviews - Add GET /api/courses/:idOrSlug/reviews (public) returning paginated reviews and aggregate avgRating - Add POST /api/courses/:idOrSlug/reviews (auth required) enforcing enrollment check before allowing a review - Include avgRating and reviewCount in GET /api/courses and GET /api/courses/:idOrSlug responses
c36afd0 to
0965cfe
Compare
|
@jerrymusaga Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #623
013_course_reviews.sql): addscourse_reviewstable withcourse_id(FK →courses.id),learner_address,rating(1–5 CHECK),review_text(nullable),created_at, and aUNIQUE(course_id, learner_address)constraint to prevent duplicate reviews. Includes rollback file.GET /api/courses/:idOrSlug/reviews(public): returns paginated reviews plus aggregateavgRatingandtotalfor any published course.POST /api/courses/:idOrSlug/reviews(auth required): validates enrollment, enforces 1–5 rating, sanitizes review text (plain text only, max 2000 chars), and returns 409 on duplicate via the DB unique constraint.GET /api/coursesandGET /api/courses/:idOrSlug: now includeavgRating(rounded to 1 decimal,nullif no reviews) andreviewCountfields via aLEFT JOIN course_reviews.Test plan
npm run migrateinserver/to apply013_course_reviews.sqlGET /api/courses— confirmavgRatingandreviewCountfields appear on each course objectGET /api/courses/:slug/reviewswith no reviews — expect{ data: [], total: 0, avgRating: null }POST /api/courses/:slug/reviewswithout Bearer token — expect 401POST /api/courses/:slug/reviewswith a valid token but not enrolled — expect 403POST /api/courses/:slug/reviewswith a valid enrolled token and{ "rating": 4, "reviewText": "Great course!" }— expect 201GET /api/courses/:slug/reviewsafter submission — confirm review appears andavgRatingis correctPOSTwithrating: 0orrating: 6— expect 400npm run migrate:rollback— confirm table is dropped cleanly