Class CourseController

java.lang.Object
com.ericbouchut.learndev.course.CourseController

@Controller public class CourseController extends Object
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

    Constructors
    Constructor
    Description
    CourseController(CourseService courseService, EnrollmentService enrollmentService, MarkdownRenderer markdownRenderer, UserRepository users)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    catalogue(Principal principal, org.springframework.ui.Model model)
    Display the catalogue of published courses, with the logged-in student's active enrollments marked.
    detail(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.
    drop(Long courseId, Principal principal)
    Drop the student from the course, then redirect back to the course page with a dropped confirmation flag (PRG).
    enroll(Long courseId, Principal principal)
    Register the student in the course, then redirect back to the course page with an enrolled confirmation flag (PRG).
    lesson(Long courseId, 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • 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 student
      model - 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 show
      principal - 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 an enrolled confirmation flag (PRG).
      Parameters:
      courseId - the course to join
      principal - 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 a dropped confirmation flag (PRG).
      Parameters:
      courseId - the course to leave
      principal - 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 an enroll-required hint instead of a 403: the Register button is right there.
      Parameters:
      courseId - the course the lesson belongs to
      lessonId - the lesson to read
      principal - the logged-in student
      model - 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