Simplify the frontend workflow by allowing sequential content generation using courseId instead of managing subtopicIds.
GET /api/interactive/course/:courseId/next
- Auth: Require valid user token.
- Lookup: Find the first subtopic for this course that is NOT completed by the user.
- Join
subtopics->units->courses. - Left Join
user_subtopic_progressonuser_idandsubtopic_id. - Order by
units.position,subtopics.position. - Condition:
user_subtopic_progress.is_completed IS NULL OR user_subtopic_progress.is_completed = FALSE.
- Join
- Action:
- If no incomplete subtopic found -> Return
{ message: "Course Completed!" }. - If found -> Redirect to (or reuse logic of)
startSession(subtopicId).- This ensures content is generated if missing.
- Returns content, questions, and progress.
- If no incomplete subtopic found -> Return
- Controller: Add
getNextSubtopictointeractiveController.js. - Routes: Add
router.get("/course/:courseId/next", ...)tointeractive.js.- Important: Place this before
/:subtopicIdif the pattern matches, or use a distinct path. Sincecourse/:idis distinct from:id(UUID), it's safe, but specific paths first is best practice.
- Important: Place this before
Frontend just has a "Start Learning" or "Next" button that calls this one endpoint. It automatically advances the user through the course.