Class RoomController

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

@Controller public class RoomController extends Object
Defines the behaviour of the web server for the path /rooms.
  • Field Details

  • Constructor Details

  • Method Details

    • getRooms

      @GetMapping({"/r\u00e4ume","/en/rooms"}) public String getRooms(@RequestParam(name="page",defaultValue="0") int page, @Max(20L) @RequestParam(name="size",defaultValue="5") @Max(20L) int size, @NonNull @RequestParam(name="sortBy",defaultValue="id") @NonNull String sortBy, @RequestParam(name="ascending",defaultValue="true") boolean ascending, @Nullable @RequestParam(name="status",required=false) @Nullable RoomStatus status, @Nullable @RequestParam(name="floor",required=false) @Nullable Integer floor, @Nullable @RequestParam(name="accessibility",required=false) @Nullable Accessibility accessibility, @NonNull @NonNull org.springframework.ui.Model model)
      Handles GET requests to /rooms. Retrieves a paginated subset of all Rooms according to the URL parameters given.
      Parameters:
      page - The index of the page requested.
      size - How many Reservation items each page in the pagination has.
      sortBy - Which of the Rooms' 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.
      status - If set, only Rooms with the given RoomStatus during the next 15 minutes will be returned.
      floor - If set, only Rooms on the specified floor will be returned.
      accessibility - If set, only Rooms with at least the specified Accessibility as the Room.accessibility will be returned.
      model - Will be filled with the data for the Thymeleaf template.
      Returns:
      The reservations.html page with the requested reservations.
    • getRoom

      @ExceptionHandler(IllegalStateException.class) @GetMapping({"/r\u00e4ume/{number}","/en/rooms/{number}"}) public String getRoom(@NonNull @PathVariable @NonNull String number, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException
      Handles GET requests to /räume/{number}. Retrieves a specific Room denoted by the path parameter number.
      Parameters:
      number - The path parameter {number} denoting a specific Room.
      model - Will be filled with the data for the Thymeleaf template.
      Returns:
      The room.html template filled with the requested Room.
      Throws:
      NotFoundException - If no Room with the given number exists.
    • getSchedule

      @GetMapping({"/r\u00e4ume/{number}/plan","/en/rooms/{number}/schedule"}) @NonNull public @NonNull String getSchedule(@NonNull @PathVariable @NonNull String number, @Nullable @Nullable LocalDate date, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException
      Handles GET requests to /rooms/{number}/schedule and returns the RoomSchedule for the Room with the given Room.number on the given LocalDate.
      Parameters:
      number - The number of the Room whose schedule shall be returned.
      date - The day for which the Room's schedule shall be built.
      model - Will be filled with the data for the Thymeleaf template.
      Returns:
      The RoomController.Template.SCHEDULE page.
      Throws:
      NotFoundException - If the given Room number does not belong to any Room.
    • getWeekSchedule

      @GetMapping({"/r\u00e4ume/{number}/plan/woche","/en/rooms/{number}/schedule/week"}) @NonNull public @NonNull String getWeekSchedule(@NonNull @PathVariable @NonNull String number, @Nullable @Nullable LocalDate date, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException
      Handles GET requests to /rooms/{number}/schedule/week and returns the RoomSchedules for each day in the given LocalDate's week for the Room with the given Room.number on the given LocalDate.
      Parameters:
      number - The number of the Room whose schedule shall be returned.
      date - The Room's schedule will be built for the week that contains this date.
      model - Will be filled with the data for the Thymeleaf template.
      Returns:
      The RoomController.Template.SCHEDULE page.
      Throws:
      NotFoundException - If the given Room number does not belong to any Room.
    • findRoom

      @GetMapping({"/r\u00e4ume/finden","/en/rooms/find"}) @NonNull public @NonNull String findRoom(@NonNull @ModelAttribute("bookRoomDTO") @NonNull BookRoomDTO reservationDTO, @NonNull @NonNull org.springframework.ui.Model model) throws IllegalStateException
      Handles GET requests to /rooms/find and returns the RoomController.Template.FIND_ROOM page which allows the user to search for Rooms based on certain criteria.
      Parameters:
      reservationDTO - Used only for form binding.
      model - Used to pass required attributes to the template.
      Returns:
      The find-room page.
      Throws:
      IllegalStateException - If the requested/available equipment is invalid for unknown reason.
    • findRoom

      @PostMapping({"/r\u00e4ume/finden","/en/rooms/find"}) @NonNull public @NonNull String findRoom(@NonNull @ModelAttribute("bookRoomDTO") @NonNull BookRoomDTO reservationDTO, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull org.springframework.ui.Model model, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response)
      Handles POST requests to /rooms/find and returns those Rooms that match the given BookRoomDTO.
      Parameters:
      reservationDTO - The data-transfer object representing the draft reservation.
      bindingResult - Used to pass error messages to the template.
      model - Used to pass attributes to the template.
      response - The web server's response to the request.
      Returns:
      The RoomController.Template.FIND_ROOM page with matching Rooms filled in.
    • addEquipment

      public void addEquipment(@NonNull @NonNull BookRoomDTO reservationDTO, @NonNull @NonNull org.springframework.ui.Model model) throws IllegalStateException
      Finds the individual-equipment types and adds them to the given BookRoomDTO (with [IndividualEquipment#count == 0]) and to the Model. Adds the common-equipment types to the Model, but not to the DTO because presence is equivalent to being selected.
      Parameters:
      reservationDTO - The data-transfer object to which the equipment types shall be added (replaced).
      model - The view model to which the individual-equipment types shall be added as the value of the individualEquipmentTypes attribute (and the common-equipment types as commonEquipmentTypes).
      Throws:
      IllegalStateException - If the equipment is invalid for unknown reason. Should never happen.
    • addEquipment

      public void addEquipment(@NonNull @NonNull org.springframework.ui.Model model)
      Adds the existing individual-equipment types as the attribute individualEquipmentTypes to the given Model and the common-equipment types as commonEquipmentTypes.
      Parameters:
      model - The Model to which the attributes shall be added.