Class EnrollmentService

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

@Service public class EnrollmentService extends Object
Student-side enrollment lifecycle (see the diagram in CONTRIBUTING.md). The (user, course) pair is the primary key, so a student has at most one enrollment row per course: enrolling again re-activates a DROPPED row instead of inserting a second one, and both operations are idempotent (re-posting a form must not fail).
  • Constructor Details

  • Method Details

    • enroll

      @Transactional public void enroll(User student, Course course)
      Enroll the student in a published course. A DROPPED enrollment is re-activated (back to ENROLLED, drop timestamp cleared, enrollment timestamp refreshed); an active one is left untouched.
      Throws:
      org.springframework.web.server.ResponseStatusException - 404 when the course is not published (only published courses accept new enrollments)
    • drop

      @Transactional public void drop(User student, Course course)
      Drop the student from a course: ENROLLED or IN_PROGRESS becomes DROPPED with a drop timestamp. No-op when the student is not enrolled, already dropped, or completed the course (the lifecycle has no transition out of COMPLETED).
    • enrollmentFor

      public Optional<Enrollment> enrollmentFor(User student, Course course)
      The enrollment of a student in a course, if any (dropped included).
    • myEnrollments

      public List<Enrollment> myEnrollments(User student)
      All enrollments of a student, dropped included (the dashboard filters).