Class ReservationAdminController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.ReservationAdminController
Defines the behaviour of the web server for the path
/admin/reservations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents templates in the resources, allowing one or several Reservations to be rendered as HTML. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull PathLocaliserUsed to resolve the URL paths in the correctLocale.private final @NonNull ReservationControllerprivate final @NonNull ReservationServiceUsed to retrieve and save Reservations from the database.private final @NonNull RoomServiceUsed for code deduplication ingetReservations(int, int, String, boolean, FilterReservationsDTO, HttpServletResponse, Model, BindingResult). -
Constructor Summary
ConstructorsConstructorDescriptionReservationAdminController(@NonNull ReservationController reservationController, @NonNull ReservationService reservationService, @NonNull RoomService roomService, @NonNull PathLocaliser pathLocaliser) Creates a newReservationAdminControllerwith the givenreservationService. -
Method Summary
Modifier and TypeMethodDescription@NonNull StringdeleteReservation(@NonNull Long id, @NonNull Locale locale) HandlesPOSTrequests to/admin/reservations/{id}/deleteand permanently removes theReservationwith the givenReservation.idfrom the database.@NonNull StringgetDeletionPage(@NonNull Long id, @NonNull org.springframework.ui.Model model) Shows a confirmation page asking the user whether they are sure they wish to permanently remove theReservationwith the givenReservation.idfrom the database.getReservation(@NonNull Long id, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/reservations/{id}.@NonNull StringgetReservations(int page, @Max(20L) int size, @NonNull String sortBy, boolean ascending, @Nullable FilterReservationsDTO filterReservationsDTO, @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull org.springframework.ui.Model model, org.springframework.validation.BindingResult bindingResult) HandlesGETrequests to/admin/reservations.@NonNull StringmassDelete(@NonNull ReservationMultiActionRequest requestDto, @NonNull org.springframework.ui.Model model) HandlesPOSTrequests to/admin/reservations/deleteand mass deletes the Reservations with the identifiers that are specified in the given data-transfer object.@NonNull StringperformMultiAction(@NonNull ReservationMultiActionRequest requestDto, @NonNull org.springframework.ui.Model model) HandlesPOSTrequests to/admin/reservations/multi-actionand performs the appropriate operation according to the givenReservationMultiActionRequest.action.
-
Field Details
-
reservationController
-
reservationService
Used to retrieve and save Reservations from the database. -
roomService
Used for code deduplication ingetReservations(int, int, String, boolean, FilterReservationsDTO, HttpServletResponse, Model, BindingResult). -
pathLocaliser
Used to resolve the URL paths in the correctLocale.
-
-
Constructor Details
-
ReservationAdminController
public ReservationAdminController(@NonNull @NonNull ReservationController reservationController, @NonNull @NonNull ReservationService reservationService, @NonNull @NonNull RoomService roomService, @NonNull @NonNull PathLocaliser pathLocaliser) Creates a newReservationAdminControllerwith the givenreservationService.
-
-
Method Details
-
getReservations
@GetMapping({"/admin/reservierungen","/en/admin/reservations"}) @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") @NonNull public @NonNull String getReservations(@RequestParam(name="page",defaultValue="0") int page, @Max(20L) @RequestParam(name="size",defaultValue="2") @Max(20L) int size, @NonNull @RequestParam(name="sortBy",defaultValue="id") @NonNull String sortBy, @RequestParam(name="ascending",defaultValue="true") boolean ascending, @Nullable @Nullable FilterReservationsDTO filterReservationsDTO, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull @NonNull org.springframework.ui.Model model, org.springframework.validation.BindingResult bindingResult) throws NotFoundException Handles
GETrequests to/admin/reservations. Retrieves a paginated subset of all Reservations according to the URL parameters given.The paging parameters
page,size,sortByandascendingare ignored if any of the filtering parameters is set (roomNumber,dateString,startTimeString,endTimeString).- Parameters:
page- The index of the page requested.size- How many Reservation items each page in the pagination has.sortBy- Which of the Reservations' 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.ascending- Whether to count from the start or from the end of the list sorted usingsortBy.filterReservationsDTO- Filtering parameters indicating what criteria the requested Reservations must fulfil.response- The web server's response to the admin's HTTP request.model- Will be filled with the data for the Thymeleaf template.bindingResult- The result of the DTO validation.- Returns:
- The
reservations.htmlpage with the requested reservations. - Throws:
NotFoundException- When the user requests the Reservations for an inexistentRoom.number.
-
getReservation
@GetMapping({"/admin/reservierungen/{id}","/en/admin/reservations/{id}"}) public String getReservation(@NonNull @PathVariable @NonNull Long id, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException HandlesGETrequests to/admin/reservations/{id}. Retrieves a specificReservationdenoted by the path parameterid.- Parameters:
id- The path parameteriddenoting a specific Reservation.model- Will be filled with the data for the Thymeleaf template.- Returns:
- The
reservation.htmltemplate filled with the requested Reservation. - Throws:
NotFoundException- If no Reservation with the given ID exists.
-
getDeletionPage
@GetMapping({"/admin/reservierungen/{id}/l\u00f6schen","/en/admin/reservations/{id}/delete"}) @NonNull public @NonNull String getDeletionPage(@NonNull @PathVariable @NonNull Long id, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException Shows a confirmation page asking the user whether they are sure they wish to permanently remove theReservationwith the givenReservation.idfrom the database.- Parameters:
id- The identifier of the Reservation that the user perhaps wishes to delete.model- Will be filled with the Reservation to be deleted, for the Thymeleaf template.- Returns:
- The
ReservationAdminController.Template.DELETEfilled with the Reservation to be deleted. - Throws:
NotFoundException- If no Reservation with the given ID exists.
-
deleteReservation
@PostMapping({"/admin/reservierungen/{id}/l\u00f6schen","/en/admin/reservations/{id}/delete"}) @NonNull public @NonNull String deleteReservation(@NonNull @PathVariable @NonNull Long id, @NonNull @NonNull Locale locale) throws NotFoundException, IllegalStateException HandlesPOSTrequests to/admin/reservations/{id}/deleteand permanently removes theReservationwith the givenReservation.idfrom the database.- Parameters:
id- The identifier of the Reservation that shall no longer be stored in the system.locale- The language that this page is being shown in.- Returns:
- Redirects to the list of all reservations.
- Throws:
NotFoundException- If no Reservation with the given ID exists.IllegalStateException- If the reservations' path is malformed.
-
performMultiAction
@PostMapping({"/admin/reservierungen/multi-aktion","/en/admin/reservations/multi-action"}) @NonNull public @NonNull String performMultiAction(@NonNull @NonNull ReservationMultiActionRequest requestDto, @NonNull @NonNull org.springframework.ui.Model model) throws de.gustavblass.commons.exceptions.IllegalArgumentException HandlesPOSTrequests to/admin/reservations/multi-actionand performs the appropriate operation according to the givenReservationMultiActionRequest.action.- Parameters:
requestDto- The data-transfer object that represents the actual request.model- Used to indicate to the template that this is an admin page.- Returns:
- A confirmation page where the user states once again that they intend to perform the operation specified.
- Throws:
de.gustavblass.commons.exceptions.IllegalArgumentException- If the given action is not supported.
-
massDelete
@PostMapping({"/admin/reservierungen/l\u00f6schen","/en/admin/reservations/delete"}) @NonNull public @NonNull String massDelete(@NonNull @NonNull ReservationMultiActionRequest requestDto, @NonNull @NonNull org.springframework.ui.Model model) throws de.gustavblass.commons.exceptions.IllegalArgumentException, NotFoundException HandlesPOSTrequests to/admin/reservations/deleteand mass deletes the Reservations with the identifiers that are specified in the given data-transfer object.- Parameters:
requestDto- The data-transfer object representing the actual request.model- Used to indicate to the template that it is not an administrator page.- Returns:
- A confirmation page telling the user that the deletion succeeded.
- Throws:
de.gustavblass.commons.exceptions.IllegalArgumentException- If the user did not confirm the operation.NotFoundException- If at least one of the given IDs does not exist in the database. Then, no Reservation is deleted.
-