Class ActorAdminController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.ActorAdminController
Defines the behaviour of the web server for the path
/admin/users.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents templates in the resources for administrators. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ActorServiceUsed to retrieve and save Actors from the database.private final @NonNull PathLocaliserUsed to resolve the URL paths in the correctLocale. -
Constructor Summary
ConstructorsConstructorDescriptionActorAdminController(@NonNull ActorService actorService, @NonNull PathLocaliser pathLocaliser) Constructs a newActorAdminController. -
Method Summary
Modifier and TypeMethodDescriptioncreateActor(@Valid LocalActorCreatedByAdminDTO dto, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull jakarta.servlet.http.HttpServletResponse response) HandlesPOSTrequests to/admin/users/addand saves a newActorbased on the form input (represented as anActorCreatedByAdminDTO) to the database.@NonNull StringgetActors(int page, @Max(20L) int size, @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @NonNull String sortBy, boolean ascending, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/users.@NonNull StringHandlesGETrequests to/adminand returns teh main administrators' interface.HandlesGETrequests to/admin/users/add.
-
Field Details
-
Constructor Details
-
ActorAdminController
public ActorAdminController(@NonNull @NonNull ActorService actorService, @NonNull @NonNull PathLocaliser pathLocaliser) Constructs a newActorAdminController.- Parameters:
actorService- TheactorService.pathLocaliser- ThepathLocaliser.
-
-
Method Details
-
getAdminArea
HandlesGETrequests to/adminand returns teh main administrators' interface.- Returns:
- The
ActorAdminController.Template.ADMIN_MAINpage.
-
getActors
@GetMapping({"/admin/benutzer","/en/admin/users"}) @NonNull public @NonNull String getActors(@RequestParam(name="page",defaultValue="0") int page, @Max(20L) @RequestParam(name="size",defaultValue="2") @Max(20L) int size, @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @RequestParam(name="sortBy",defaultValue="id") @NonNull @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @NonNull String sortBy, @RequestParam(name="ascending",defaultValue="true") boolean ascending, @NonNull @NonNull org.springframework.ui.Model model) HandlesGETrequests to/users. Retrieves a paginated subset of all Actors according to the URL parameters given.- Parameters:
page- The index of the page requested.size- How many Actor items each page in the pagination has.sortBy- Which of the Actors' fields shall be used to sort the items. Determines the order of the items and thereby also which items are present on the requested page. Must not be the password.ascending- Whether to count from the start or from the end of the list sorted usingsortBy.model- Will be filled with the data for the Thymeleaf template.- Returns:
- The
users.htmltemplate filled with the requested Actors.
-
getCreateActorForm
@GetMapping({"/admin/benutzer/hinzuf\u00fcgen","/en/admin/users/add"}) @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") public String getCreateActorForm(LocalActorCreatedByAdminDTO actor) HandlesGETrequests to/admin/users/add.- Parameters:
actor- An emptyActorCreatedByAdminDTOonly used for binding in the Thymeleaf template.- Returns:
- The admins' create-user form.
-
createActor
@PostMapping({"/admin/benutzer/hinzuf\u00fcgen","/en/admin/users/add"}) @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") public String createActor(@Valid @Valid LocalActorCreatedByAdminDTO dto, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws de.gustavblass.commons.exceptions.IllegalArgumentException, IllegalStateException Handles
POSTrequests to/admin/users/addand saves a newActorbased on the form input (represented as anActorCreatedByAdminDTO) to the database.Validates the input according to the annotations in
ActorCreatedByAdminDTO. If there are errors, localised error messages are displayed next to the corresponding input fields.If the given user name already exists, a localised error message is shown to the admin.
If the admin's
ActorRoledoes not suffice to create a user of the specified role, a localised error message is shown next to the role input field.- Parameters:
dto- The form input by the admin, represented as a data-transfer object.bindingResult- The result of the DTO validation.response- The web server's response to the admin's HTTP request.- Returns:
- In case of success: The user page (e.g.
/users/@jason). Otherwise: The form, with the original input preserved and with error messages shown. - Throws:
de.gustavblass.commons.exceptions.IllegalArgumentException- If noLocalActorCreatedByAdminDTO.passwordis set.IllegalStateException- If the user path is malformed.
-