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 RoomMapperConverts data-transfer objects to Rooms.private final RoomServiceUsed to retrieve and save Rooms from the database. -
Constructor Summary
ConstructorsConstructorDescriptionRoomAdminController(@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 StringgetCreateRoomForm(NewRoomDTO newRoomDTO, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/rooms/add.
-
Field Details
-
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 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.
-
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.
-