Class RoomAdminRestController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.RoomAdminRestController
Defines the behaviour of the API server for the path
/api/v1/admin/rooms.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull RoomMapperConverts data-transfer objects to Rooms.private final RoomServiceUsed to retrieve and save Rooms from the database. -
Constructor Summary
ConstructorsConstructorDescriptionRoomAdminRestController(@NonNull RoomService roomService, @NonNull RoomMapper roomMapper) Constructs a newRoomAdminRestControllerwith the givenroomService. -
Method Summary
Modifier and TypeMethodDescription@NonNull org.springframework.http.ResponseEntity<Void> createRoom(@Valid @NonNull NewRoomDTO dto) HandlesPOSTrequests to/api/v1/admin/roomsand adds the givenNewRoomDTOas a newRoomto the database.org.springframework.http.ResponseEntity<Void> deleteRoom(@NonNull String number) Removes theRoomwith the givenRoom.numberfrom the database, if there are no Reservations for the Room that end afterLocalDateTime.now().
-
Field Details
-
roomService
Used to retrieve and save Rooms from the database. -
roomMapper
Converts data-transfer objects to Rooms.
-
-
Constructor Details
-
RoomAdminRestController
public RoomAdminRestController(@NonNull @NonNull RoomService roomService, @NonNull @NonNull RoomMapper roomMapper) Constructs a newRoomAdminRestControllerwith the givenroomService.- Parameters:
roomService- TheroomServiceto use for database access.roomMapper- TheroomMapperto use for database access.
-
-
Method Details
-
createRoom
@PostMapping("/api/v1/admin/rooms") @NonNull public @NonNull org.springframework.http.ResponseEntity<Void> createRoom(@RequestBody @Valid @NonNull @Valid @NonNull NewRoomDTO dto) throws AlreadyExistsException, InvalidIndividualEquipmentException, InvalidCommonEquipmentException, de.gustavblass.commons.exceptions.IllegalArgumentException HandlesPOSTrequests to/api/v1/admin/roomsand adds the givenNewRoomDTOas a newRoomto 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.- Returns:
- Empty response. Only the status code indicates success. The response's
locationheader will point to the URI of the new Room. - Throws:
AlreadyExistsException- If the Room number is not unique.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.de.gustavblass.commons.exceptions.IllegalArgumentException- If the DTO conversion fails.
-
deleteRoom
@DeleteMapping("/api/v1/admin/rooms/{number}") public org.springframework.http.ResponseEntity<Void> deleteRoom(@NonNull @PathVariable @NonNull String number) throws NotFoundException, RoomStillHasReservationsException Removes theRoomwith the givenRoom.numberfrom the database, if there are no Reservations for the Room that end afterLocalDateTime.now().- Parameters:
number- The number of the Room that shall no longer be part of the system.- Returns:
- Empty response. Only the status code indicates success.
- Throws:
NotFoundException- If no Room with the given number exists.RoomStillHasReservationsException- If there are still future Reservations for the given Room.
-