Class ReservationController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.ReservationController
Defines the behaviour of the web server for the path
/book-room.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static 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.static final StringThe name of the session attribute that remembers theBookRoomDTOduring the login process.private final ReservationServiceUsed to retrieve and save Reservations from the database.private final RoomServiceUsed to retrieve Rooms from the database. -
Constructor Summary
ConstructorsConstructorDescriptionReservationController(@NonNull ReservationService reservationService, @NonNull RoomService roomService, @NonNull PathLocaliser pathLocaliser) Creates a newReservationController. -
Method Summary
Modifier and TypeMethodDescription@NonNull StringbookRoom(@NonNull @Valid BookRoomDTO reservationDTO, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull org.springframework.ui.Model model, @NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull jakarta.servlet.http.HttpSession session, @NonNull org.springframework.web.bind.support.SessionStatus sessionStatus) @NonNull StringdeleteReservation(@NonNull Long id, @NonNull Locale locale) HandlesPOSTrequests to/reservations/{id}/deleteand permanently removes the currentActor'sReservationwith 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 theirReservationwith the givenReservation.idfrom the database.getReservation(@NonNull Long id, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/reservations/{id}.@NonNull StringgetReservationPage(@NonNull BookRoomDTO reservationDTO, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/en/book-roomand presents the end-user a form that allows them to book a room.@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 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, @NonNull Function<org.springframework.data.domain.PageRequest, org.springframework.data.domain.Page<Reservation>> reservationPager, boolean isAdminPage) Retrieves a paginated subset of all Reservations according to the URL parameters given.@NonNull StringmassDelete(@NonNull ReservationMultiActionRequest requestDto, @NonNull org.springframework.ui.Model model) HandlesPOSTrequests to/reservations/deleteand [mass deletes][ReservationService#deleteOwnReservations(Iterable)(Iterable)] the currentActor's 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/reservations/multi-actionand performs the appropriate operation according to the givenReservationMultiActionRequest.action.
-
Field Details
-
PENDING_FORM_DATA
The name of the session attribute that remembers theBookRoomDTOduring the login process.- See Also:
-
reservationService
Used to retrieve and save Reservations from the database. -
roomService
Used to retrieve Rooms from the database. -
pathLocaliser
Used to resolve the URL paths in the correctLocale.
-
-
Constructor Details
-
ReservationController
public ReservationController(@NonNull @NonNull ReservationService reservationService, @NonNull @NonNull RoomService roomService, @NonNull @NonNull PathLocaliser pathLocaliser) Creates a newReservationController.- Parameters:
reservationService- ThereservationService.roomService- TheroomService.pathLocaliser- ThepathLocaliser.
-
-
Method Details
-
getReservations
@GetMapping({"/reservierungen","/en/reservations"}) @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.
-
getReservations
@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, @NonNull @NonNull Function<org.springframework.data.domain.PageRequest, org.springframework.data.domain.Page<Reservation>> reservationPager, boolean isAdminPage) throws NotFoundException 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.reservationPager- Fetches the requested Reservations from the database according to thePageRequest.isAdminPage- Will be passed to the template via theModel.- Returns:
- The
reservations.htmlpage with the requested reservations. - Throws:
NotFoundException- When the user requests the Reservations for an inexistentRoom.number.
-
getReservation
@GetMapping({"/reservierungen/{id}","/en/reservations/{id}"}) public String getReservation(@NonNull @PathVariable @NonNull Long id, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException HandlesGETrequests to/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({"/reservierungen/{id}/l\u00f6schen","/en/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 theirReservationwith 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({"/reservierungen/{id}/l\u00f6schen","/en/reservations/{id}/delete"}) @NonNull public @NonNull String deleteReservation(@NonNull @PathVariable @NonNull Long id, @NonNull @NonNull Locale locale) throws NotFoundException, IllegalStateException HandlesPOSTrequests to/reservations/{id}/deleteand permanently removes the currentActor'sReservationwith 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({"/reservierungen/multi-aktion","/en/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/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({"/reservierungen/l\u00f6schen","/en/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/reservations/deleteand [mass deletes][ReservationService#deleteOwnReservations(Iterable)(Iterable)] the currentActor's Reservations with the identifiers that are specified in the given data-transfer object.- Parameters:
requestDto- The data-transfer object representing the actual request.model- Indicates 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.
-
getReservationPage
@GetMapping({"/reservieren","/en/book-room"}) @NonNull public @NonNull String getReservationPage(@NonNull @NonNull BookRoomDTO reservationDTO, @NonNull @NonNull org.springframework.ui.Model model) HandlesGETrequests to/en/book-roomand presents the end-user a form that allows them to book a room.- Parameters:
reservationDTO- Used to fill the form with default values (or the values filled in prior to login).model- Will be filled with the data for the Thymeleaf template.- Returns:
- The
ReservationController.Template.BOOK_ROOMfilled with the default values.
-
bookRoom
@PostMapping({"/reservieren","/en/book-room"}) @NonNull public @NonNull String bookRoom(@NonNull @Valid @ModelAttribute("bookRoomDTO") @NonNull @Valid BookRoomDTO reservationDTO, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull org.springframework.ui.Model model, @NonNull @NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull @NonNull jakarta.servlet.http.HttpSession session, @NonNull @NonNull org.springframework.web.bind.support.SessionStatus sessionStatus) throws IllegalStateException, de.gustavblass.commons.exceptions.IllegalArgumentException - Parameters:
reservationDTO- The data-transfer object representing the Reservation that shall be placed. Corresponds to the form input.bindingResult- The result of the DTO validation.model- Will be filled with the data for the Thymeleaf template.request- The HTTP request sent to the server.response- The web server's response to the admin's HTTP request.session- TheHttpSessionof the user making the request.sessionStatus- Used to delete the DTO from the session attributes.- Returns:
- In case of success, redirects to the room-page of the
FilterReservationsDTO.room. In case of errors, returns theReservationController.Template.BOOK_ROOMwith fitting error messages. - Throws:
de.gustavblass.commons.exceptions.IllegalArgumentException- In case of unexpected validation errors. Should never happen, thanks to theValidannotation on theBindingResult.IllegalStateException- If the user cannot be authenticated for unknown reasons or if the room/schedule path is malformed.
-