Package com.ericbouchut.learndev.course
Class CourseController
java.lang.Object
com.ericbouchut.learndev.course.CourseController
Web endpoints of the student course experience: the published
course catalogue, the course detail page, and the enroll/drop actions.
Access requires authentication (
/courses/** in the security
rules); visibility of individual courses is decided by
CourseService and the enrollment lifecycle by
EnrollmentService.-
Constructor Summary
ConstructorsConstructorDescriptionCourseController(CourseService courseService, EnrollmentService enrollmentService, MarkdownRenderer markdownRenderer, UserRepository users) -
Method Summary
Modifier and TypeMethodDescriptionDisplay the catalogue of published courses, with the logged-in student's active enrollments marked.Display one course with its published lessons and the enroll or quit action matching the student's enrollment state.Drop the student from the course, then redirect back to the course page with adroppedconfirmation flag (PRG).Register the student in the course, then redirect back to the course page with anenrolledconfirmation flag (PRG).Display one published lesson to an enrolled student, with the lesson Markdown rendered to sanitized HTML and previous/next links in reading order.
-
Constructor Details
-
CourseController
public CourseController(CourseService courseService, EnrollmentService enrollmentService, MarkdownRenderer markdownRenderer, UserRepository users)
-
-
Method Details
-
catalogue
@GetMapping("/courses") public String catalogue(Principal principal, org.springframework.ui.Model model) Display the catalogue of published courses, with the logged-in student's active enrollments marked.- Parameters:
principal- the logged-in studentmodel- receives the courses and the enrolled course ids- Returns:
- the catalogue view name
-
detail
@GetMapping("/courses/{courseId}") public String detail(@PathVariable Long courseId, Principal principal, org.springframework.ui.Model model) Display one course with its published lessons and the enroll or quit action matching the student's enrollment state.- Parameters:
courseId- the course to showprincipal- the logged-in student (drives visibility)model- receives the course, its readable lessons, and the student's enrollment (null when never enrolled)- Returns:
- the course detail view name
-
enroll
@PostMapping("/courses/{courseId}/enroll") public String enroll(@PathVariable Long courseId, Principal principal) Register the student in the course, then redirect back to the course page with anenrolledconfirmation flag (PRG).- Parameters:
courseId- the course to joinprincipal- the logged-in student- Returns:
- a redirect to the course detail page
-
drop
@PostMapping("/courses/{courseId}/drop") public String drop(@PathVariable Long courseId, Principal principal) Drop the student from the course, then redirect back to the course page with adroppedconfirmation flag (PRG).- Parameters:
courseId- the course to leaveprincipal- the logged-in student- Returns:
- a redirect to the course detail page
-
lesson
@GetMapping("/courses/{courseId}/lessons/{lessonId}") public String lesson(@PathVariable Long courseId, @PathVariable Long lessonId, Principal principal, org.springframework.ui.Model model) Display one published lesson to an enrolled student, with the lesson Markdown rendered to sanitized HTML and previous/next links in reading order. A student who is not actively enrolled is sent back to the course page with anenroll-requiredhint instead of a 403: the Register button is right there.- Parameters:
courseId- the course the lesson belongs tolessonId- the lesson to readprincipal- the logged-in studentmodel- receives the course, lesson, rendered content, and the previous/next lessons (null at the edges)- Returns:
- the lesson view name, or a redirect when not enrolled
-