Package com.ericbouchut.learndev.admin
Class AdminController
java.lang.Object
com.ericbouchut.learndev.admin.AdminController
Web endpoints of the administration area under
/admin/**
(gated to ROLE_ADMIN by the security rules): the account list,
instructor account creation, and account archiving. Rules and the audit
trail live in AccountAdminService.-
Constructor Summary
ConstructorsConstructorDescriptionAdminController(AccountAdminService accounts, UserRepository users, CourseRepository courses, InstructorCourseService instructorCourses) -
Method Summary
Modifier and TypeMethodDescriptionarchiveAccount(UUID userId, Principal principal, jakarta.servlet.http.HttpServletRequest request) Archive an account (PRG with anarchivedflag).courseList(org.springframework.ui.Model model) Display every course, any status, any instructor, with its lessons (content moderation view).createInstructor(@Valid RegisterForm form, org.springframework.validation.BindingResult binding, Principal principal, jakarta.servlet.http.HttpServletRequest request) Create an instructor account.newInstructorForm(org.springframework.ui.Model model) Display the instructor account creation form.reactivateAccount(UUID userId, Principal principal, jakarta.servlet.http.HttpServletRequest request) Reactivate an account (PRG with areactivatedflag).transitionCourse(Long courseId, String action, Principal principal, jakarta.servlet.http.HttpServletRequest request) Archive or restore any course, bypassing the instructor ownership rule (the lifecycle guards still apply).transitionLesson(Long courseId, Long lessonId, String action, Principal principal, jakarta.servlet.http.HttpServletRequest request) Archive or restore any lesson of a course, bypassing the instructor ownership rule.unlockAccount(UUID userId, Principal principal, jakarta.servlet.http.HttpServletRequest request) Unlock an account locked by failed logins (PRG with anunlockedflag).userList(org.springframework.ui.Model model) Display every account with its roles and active flag.
-
Constructor Details
-
AdminController
public AdminController(AccountAdminService accounts, UserRepository users, CourseRepository courses, InstructorCourseService instructorCourses)
-
-
Method Details
-
userList
Display every account with its roles and active flag.- Parameters:
model- receives the accounts- Returns:
- the account list view name
-
newInstructorForm
@GetMapping("/users/new-instructor") public String newInstructorForm(org.springframework.ui.Model model) Display the instructor account creation form.- Parameters:
model- receives an empty form- Returns:
- the account form view name
-
createInstructor
@PostMapping("/users/new-instructor") public String createInstructor(@Valid @ModelAttribute("form") @Valid RegisterForm form, org.springframework.validation.BindingResult binding, Principal principal, jakarta.servlet.http.HttpServletRequest request) Create an instructor account. Duplicate username/email surface as field errors, like self-registration.- Parameters:
form- the submitted form, validated by@Validbinding- collects validation and duplicate-field errorsprincipal- the logged-in adminrequest- provides the client IP for the audit trail- Returns:
- a redirect to the account list, or the re-rendered form
-
archiveAccount
@PostMapping("/users/{userId}/archive") public String archiveAccount(@PathVariable UUID userId, Principal principal, jakarta.servlet.http.HttpServletRequest request) Archive an account (PRG with anarchivedflag).- Parameters:
userId- the account to archiveprincipal- the logged-in admin (self-archive guard)request- provides the client IP for the audit trail- Returns:
- a redirect to the account list
-
unlockAccount
@PostMapping("/users/{userId}/unlock") public String unlockAccount(@PathVariable UUID userId, Principal principal, jakarta.servlet.http.HttpServletRequest request) Unlock an account locked by failed logins (PRG with anunlockedflag).- Parameters:
userId- the account to unlockprincipal- the logged-in adminrequest- provides the client IP for the audit trail- Returns:
- a redirect to the account list
-
reactivateAccount
@PostMapping("/users/{userId}/reactivate") public String reactivateAccount(@PathVariable UUID userId, Principal principal, jakarta.servlet.http.HttpServletRequest request) Reactivate an account (PRG with areactivatedflag).- Parameters:
userId- the account to reactivateprincipal- the logged-in adminrequest- provides the client IP for the audit trail- Returns:
- a redirect to the account list
-
courseList
Display every course, any status, any instructor, with its lessons (content moderation view).- Parameters:
model- receives the courses and their lessons- Returns:
- the course moderation view name
-
transitionCourse
@PostMapping("/courses/{courseId}/{action:archive|restore}") public String transitionCourse(@PathVariable Long courseId, @PathVariable String action, Principal principal, jakarta.servlet.http.HttpServletRequest request) Archive or restore any course, bypassing the instructor ownership rule (the lifecycle guards still apply). PRG back to the list.- Parameters:
courseId- the course to transitionaction-archiveorrestoreprincipal- the logged-in adminrequest- provides the client IP for the audit trail- Returns:
- a redirect to the course moderation view
-
transitionLesson
@PostMapping("/courses/{courseId}/lessons/{lessonId}/{action:archive|restore}") public String transitionLesson(@PathVariable Long courseId, @PathVariable Long lessonId, @PathVariable String action, Principal principal, jakarta.servlet.http.HttpServletRequest request) Archive or restore any lesson of a course, bypassing the instructor ownership rule. PRG back to the list.- Parameters:
courseId- the course the lesson belongs tolessonId- the lesson to transitionaction-archiveorrestoreprincipal- the logged-in adminrequest- provides the client IP for the audit trail- Returns:
- a redirect to the course moderation view
-