Class RoomAdminController

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.RoomAdminController

@Controller public class RoomAdminController extends Object
Defines the behaviour of the API server for the path /admin/rooms.
  • Field Details

  • Constructor Details

  • Method Details

    • getCreateRoomForm

      @GetMapping({"/admin/r\u00e4ume/hinzuf\u00fcgen","/en/admin/rooms/add"}) @NonNull public @NonNull String getCreateRoomForm(NewRoomDTO newRoomDTO, @NonNull @NonNull org.springframework.ui.Model model)
      Handles GET requests to /admin/rooms/add.
      Parameters:
      newRoomDTO - An empty NewRoomDTO only used for binding in the Thymeleaf template.
      model - Used to add the existing EquipmentTypes to the form.
      Returns:
      The admins' create-room form.
    • getRooms

      @GetMapping({"/admin/r\u00e4ume","/en/admin/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)
    • getRoom

      @GetMapping({"/admin/r\u00e4ume/{number}","/en/admin/rooms/{number}"}) public String getRoom(@NonNull @PathVariable @NonNull String number, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException
      Throws:
      NotFoundException
    • createRoom

      @PostMapping({"/admin/r\u00e4ume/hinzuf\u00fcgen","/en/admin/rooms/add"}) @NonNull public @NonNull String createRoom(@Valid @NonNull @Valid @NonNull NewRoomDTO dto, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull org.springframework.ui.Model model, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws IllegalStateException, InvalidIndividualEquipmentException, InvalidCommonEquipmentException, de.gustavblass.commons.exceptions.IllegalArgumentException
      Handles POST requests to /admin/rooms and adds the given NewRoomDTO as a new Room to the database.
      Parameters:
      dto - The data-transfer object that represents the new Room. Must be valid according to the annotations on the class fields. Must have a unique (new) Room.number.
      bindingResult - The result of the DTO validation.
      model - Used to add the existing EquipmentTypes to the form.
      response - The web server's response to the admin's HTTP request.
      Returns:
      In case of success: The room page (e.g. /rooms/42). Otherwise: The form, with the original input preserved and with error messages shown.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the DTO conversion fails.
      InvalidIndividualEquipmentException - If one of the Room's IndividualEquipmentTypes does not exist in the database.
      InvalidCommonEquipmentException - If one of the Room's CommonEquipmentTypes does not exist in the database.
      IllegalStateException - If the room path is malformed.
    • getEditRoomForm

      @GetMapping({"/admin/r\u00e4ume/{roomNumber}/bearbeiten","/en/admin/rooms/{roomNumber}/edit"}) @NonNull public @NonNull String getEditRoomForm(@NonNull @PathVariable @NonNull String roomNumber, @NonNull @NonNull NewRoomDTO newRoomDTO, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException, de.gustavblass.commons.exceptions.IllegalArgumentException
      Handles GET requests to /admin/rooms/{roomNumber}/edit and returns the RoomAdminController.Template.EDIT_FORM for the Room with the specified Room.number.
      Parameters:
      roomNumber - The room number of the Room whose edit form shall be returned.
      newRoomDTO - An empty NewRoomDTO only used for binding in the Thymeleaf template.
      model - Used to add the existing EquipmentTypes to the form.
      Returns:
      The admins' create-room form.
      Throws:
      NotFoundException - If the room number does not exist.
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the Room could not be converted into a data-transfer object.
    • editRoom

      @PostMapping({"/admin/r\u00e4ume/{roomNumber}/bearbeiten","/en/admin/rooms/{roomNumber}/edit"}) @NonNull public @NonNull String editRoom(@NonNull @PathVariable @NonNull String roomNumber, @Valid @NonNull @Valid @NonNull NewRoomDTO dto, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull org.springframework.ui.Model model, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws IllegalStateException, InvalidIndividualEquipmentException, InvalidCommonEquipmentException, de.gustavblass.commons.exceptions.IllegalArgumentException, NotFoundException
      Handles POST requests to /admin/rooms/{roomNumber}/edit and saves the given edited data-transfer object to the database.
      Parameters:
      roomNumber - The (old) number of the Room that shall be edited.
      dto - The data-transfer object that represents the edited Room. Must be valid according to the annotations on the class fields. If the Room.number was changed, it must be unique.
      bindingResult - The result of the DTO validation.
      model - Used to add the existing EquipmentTypes to the form.
      response - The web server's response to the admin's HTTP request.
      Returns:
      In case of success: The room page (e.g. /rooms/42). Otherwise: The RoomAdminController.Template.EDIT_FORM, with the original input preserved and with error messages shown.
      Throws:
      NotFoundException - If the room number does not exist.
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the DTO conversion fails.
      InvalidIndividualEquipmentException - If one of the Room's IndividualEquipmentTypes does not exist in the database.
      InvalidCommonEquipmentException - If one of the Room's CommonEquipmentTypes does not exist in the database.
      IllegalStateException - If the room path is malformed.
    • getDeletionPage

      @GetMapping({"/admin/r\u00e4ume/{number}/l\u00f6schen","/en/admin/rooms/{number}/delete"}) @NonNull public @NonNull String getDeletionPage(@NonNull @PathVariable @NonNull String number, @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 the Room with the given Room.number from the database.
      Parameters:
      number - The identifier of the Room that the user perhaps wishes to delete.
      model - Will be filled with the Room to be deleted, for the Thymeleaf template.
      Returns:
      The RoomAdminController.Template.DELETE_FORM filled with the Room to be deleted.
      Throws:
      NotFoundException - If no Room with the given number exists.
    • deleteRoom

      @PostMapping({"/admin/r\u00e4ume/{number}/l\u00f6schen","/en/admin/rooms/{number}/delete"}) @NonNull public @NonNull String deleteRoom(@NonNull @PathVariable @NonNull String number, @NonNull @NonNull Locale locale) throws NotFoundException, IllegalStateException, RoomStillHasReservationsException

      Handles POST requests to /admin/rooms/{number}/delete and permanently removes the Room with the given Room.number from the database.

      Deletes all past Reservations.

      Parameters:
      number - The number of the Room 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 rooms.
      Throws:
      NotFoundException - If no Room with the given page exists.
      IllegalStateException - If the rooms' path is malformed.
      RoomStillHasReservationsException - If there are still future Reservations with the given Room as the Reservation.room in the database. In this case, no past Reservations are deleted.