Class RoomAdminController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.RoomAdminController
Defines the behaviour of the API server for the path
/admin/rooms.-
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 EquipmentServiceUsed to fetch existing EquipmentTypes from the database.private final @NonNull PathLocaliserUsed to resolve the URL paths in the correctLocale.private final @NonNull RoomControllerprivate final @NonNull RoomMapperConverts data-transfer objects to Rooms.private final RoomServiceUsed to retrieve and save Rooms from the database. -
Constructor Summary
ConstructorsConstructorDescriptionRoomAdminController(@NonNull RoomController roomController, @NonNull RoomService roomService, @NonNull EquipmentService equipmentService, @NonNull RoomMapper roomMapper, @NonNull PathLocaliser pathLocaliser) Constructs a newRoomAdminControllerwith the givenroomService. -
Method Summary
Modifier and TypeMethodDescription@NonNull StringcreateRoom(@Valid @NonNull NewRoomDTO dto, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull org.springframework.ui.Model model, @NonNull jakarta.servlet.http.HttpServletResponse response) @NonNull StringdeleteRoom(@NonNull String number, @NonNull Locale locale) HandlesPOSTrequests to/admin/rooms/{number}/deleteand permanently removes theRoomwith the givenRoom.numberfrom the database.@NonNull StringeditRoom(@NonNull String roomNumber, @Valid @NonNull NewRoomDTO dto, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull org.springframework.ui.Model model, @NonNull jakarta.servlet.http.HttpServletResponse response) HandlesPOSTrequests to/admin/rooms/{roomNumber}/editand saves the given edited data-transfer object to the database.@NonNull StringgetCreateRoomForm(NewRoomDTO newRoomDTO, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/rooms/add.@NonNull StringgetDeletionPage(@NonNull String number, @NonNull org.springframework.ui.Model model) Shows a confirmation page asking the user whether they are sure they wish to permanently remove theRoomwith the givenRoom.numberfrom the database.@NonNull StringgetEditRoomForm(@NonNull String roomNumber, @NonNull NewRoomDTO newRoomDTO, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/rooms/{roomNumber}/editand returns theRoomAdminController.Template.EDIT_FORMfor theRoomwith the specifiedRoom.number.Alias forRoomController.getRoom(String, Model).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)
-
Field Details
-
roomController
-
roomService
Used to retrieve and save Rooms from the database. -
equipmentService
Used to fetch existing EquipmentTypes from the database.- See Also:
-
roomMapper
Converts data-transfer objects to Rooms. -
pathLocaliser
Used to resolve the URL paths in the correctLocale.
-
-
Constructor Details
-
RoomAdminController
public RoomAdminController(@NonNull @NonNull RoomController roomController, @NonNull @NonNull RoomService roomService, @NonNull @NonNull EquipmentService equipmentService, @NonNull @NonNull RoomMapper roomMapper, @NonNull @NonNull PathLocaliser pathLocaliser) Constructs a newRoomAdminControllerwith the givenroomService.- Parameters:
roomService- TheroomServiceto use for database access.equipmentService- TheequipmentServiceto use for database access.roomMapper- TheroomMapper.pathLocaliser- ThepathLocaliserto use for localising paths.
-
-
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) HandlesGETrequests to/admin/rooms/add.- Parameters:
newRoomDTO- An emptyNewRoomDTOonly 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 Alias forRoomController.getRoom(String, Model).- 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 - 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 HandlesGETrequests to/admin/rooms/{roomNumber}/editand returns theRoomAdminController.Template.EDIT_FORMfor theRoomwith the specifiedRoom.number.- Parameters:
roomNumber- The room number of the Room whose edit form shall be returned.newRoomDTO- An emptyNewRoomDTOonly 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 HandlesPOSTrequests to/admin/rooms/{roomNumber}/editand 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 theRoom.numberwas 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: TheRoomAdminController.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 theRoomwith the givenRoom.numberfrom 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_FORMfilled 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
POSTrequests to/admin/rooms/{number}/deleteand permanently removes theRoomwith the givenRoom.numberfrom 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 theReservation.roomin the database. In this case, no past Reservations are deleted.
-