Class RoomController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.RoomController
Defines the behaviour of the web server for the path
/rooms.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumRepresents templates in the resources, allowing one or several Rooms to be rendered as HTML. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull EquipmentServiceUsed to find the existing individual-equipment types and the existing common-equipment types.private final @NonNull RoomService -
Constructor Summary
ConstructorsConstructorDescriptionRoomController(@NonNull RoomService roomService, @NonNull EquipmentService equipmentService) Constructs a newRoomController. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEquipment(@NonNull BookRoomDTO reservationDTO, @NonNull org.springframework.ui.Model model) Finds the individual-equipment types and adds them to the givenBookRoomDTO(with [IndividualEquipment#count == 0]) and to theModel.voidaddEquipment(@NonNull org.springframework.ui.Model model) Adds the existing individual-equipment types as the attributeindividualEquipmentTypesto the givenModeland the common-equipment types ascommonEquipmentTypes.@NonNull StringfindRoom(@NonNull BookRoomDTO reservationDTO, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/rooms/findand returns theRoomController.Template.FIND_ROOMpage which allows the user to search for Rooms based on certain criteria.@NonNull StringfindRoom(@NonNull BookRoomDTO reservationDTO, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull org.springframework.ui.Model model, @NonNull jakarta.servlet.http.HttpServletResponse response) HandlesGETrequests to/räume/{number}.getRooms(int page, @Max(20L) int size, @NonNull String sortBy, boolean ascending, @Nullable RoomStatus status, @Nullable Integer floor, @Nullable Accessibility accessibility, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/rooms.@NonNull StringgetSchedule(@NonNull String number, @Nullable LocalDate date, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/rooms/{number}/scheduleand returns theRoomSchedulefor theRoomwith the givenRoom.numberon the givenLocalDate.@NonNull StringgetWeekSchedule(@NonNull String number, @Nullable LocalDate date, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/rooms/{number}/schedule/weekand returns the RoomSchedules for each day in the givenLocalDate's week for theRoomwith the givenRoom.numberon the givenLocalDate.
-
Field Details
-
roomService
-
equipmentService
Used to find the existing individual-equipment types and the existing common-equipment types.
-
-
Constructor Details
-
RoomController
public RoomController(@NonNull @NonNull RoomService roomService, @NonNull @NonNull EquipmentService equipmentService) Constructs a newRoomController.- Parameters:
roomService- TheroomServicefor database access.equipmentService- TheequipmentService.
-
-
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) HandlesGETrequests 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 usingsortBy.status- If set, only Rooms with the givenRoomStatusduring 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 specifiedAccessibilityas theRoom.accessibilitywill be returned.model- Will be filled with the data for the Thymeleaf template.- Returns:
- The
reservations.htmlpage 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 HandlesGETrequests to/räume/{number}. Retrieves a specificRoomdenoted by the path parameternumber.- Parameters:
number- The path parameter{number}denoting a specific Room.model- Will be filled with the data for the Thymeleaf template.- Returns:
- The
room.htmltemplate 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 HandlesGETrequests to/rooms/{number}/scheduleand returns theRoomSchedulefor theRoomwith the givenRoom.numberon the givenLocalDate.- 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.SCHEDULEpage. - 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 HandlesGETrequests to/rooms/{number}/schedule/weekand returns the RoomSchedules for each day in the givenLocalDate's week for theRoomwith the givenRoom.numberon the givenLocalDate.- 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.SCHEDULEpage. - 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 HandlesGETrequests to/rooms/findand returns theRoomController.Template.FIND_ROOMpage 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) - 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_ROOMpage 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 givenBookRoomDTO(with [IndividualEquipment#count == 0]) and to theModel. 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 theindividualEquipmentTypesattribute (and the common-equipment types ascommonEquipmentTypes).- 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 attributeindividualEquipmentTypesto the givenModeland the common-equipment types ascommonEquipmentTypes.- Parameters:
model- The Model to which the attributes shall be added.
-