Class ReservationController

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.ReservationController

@Controller @SessionAttributes("bookRoomDTO") public class ReservationController extends Object
Defines the behaviour of the web server for the path /book-room.
  • Field Details

    • PENDING_FORM_DATA

      public static final String PENDING_FORM_DATA
      The name of the session attribute that remembers the BookRoomDTO during the login process.
      See Also:
    • reservationService

      private final ReservationService reservationService
      Used to retrieve and save Reservations from the database.
    • roomService

      private final RoomService roomService
      Used to retrieve Rooms from the database.
    • pathLocaliser

      @NonNull private final @NonNull PathLocaliser pathLocaliser
      Used to resolve the URL paths in the correct Locale.
  • Constructor Details

  • 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 GET requests to /admin/reservations. Retrieves a paginated subset of all Reservations according to the URL parameters given.

      The paging parameters page, size, sortBy and ascending are 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 using sortBy.
      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.html page with the requested reservations.
      Throws:
      NotFoundException - When the user requests the Reservations for an inexistent Room.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, sortBy and ascending are 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 using sortBy.
      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 the PageRequest.
      isAdminPage - Will be passed to the template via the Model.
      Returns:
      The reservations.html page with the requested reservations.
      Throws:
      NotFoundException - When the user requests the Reservations for an inexistent Room.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
      Handles GET requests to /reservations/{id}. Retrieves a specific Reservation denoted by the path parameter id.
      Parameters:
      id - The path parameter id denoting a specific Reservation.
      model - Will be filled with the data for the Thymeleaf template.
      Returns:
      The reservation.html template 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 their Reservation with the given Reservation.id from 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.DELETE filled 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
      Handles POST requests to /reservations/{id}/delete and permanently removes the current Actor's Reservation with the given Reservation.id from 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
      Handles POST requests to /reservations/multi-action and performs the appropriate operation according to the given ReservationMultiActionRequest.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
      Handles POST requests to /reservations/delete and [mass deletes][ReservationService#deleteOwnReservations(Iterable)(Iterable)] the current Actor'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)
      Handles GET requests to /en/book-room and 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_ROOM filled 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
      Handles POST requests to /en/book-room and places a new Reservation based on the given BookRoomDTO.
      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 - The HttpSession of 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 the ReservationController.Template.BOOK_ROOM with fitting error messages.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - In case of unexpected validation errors. Should never happen, thanks to the Valid annotation on the BindingResult.
      IllegalStateException - If the user cannot be authenticated for unknown reasons or if the room/schedule path is malformed.