Class ReservationRestController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.ReservationRestController
Defines the behaviour of the API server for the path
/api/v1/book-room.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumPre-compiled UriTemplates for HATEOAS-compliant API responses. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull ReservationMapperConverts Reservations to data-transfer objects.private final ReservationServiceUsed to retrieve and save Reservations from the database. -
Constructor Summary
ConstructorsConstructorDescriptionReservationRestController(@NonNull ReservationService reservationService, @NonNull ReservationMapper reservationMapper) Creates a newReservationRestController. -
Method Summary
Modifier and TypeMethodDescription@NonNull org.springframework.hateoas.EntityModel<ReservationDTO> bookRoom(@NonNull @Valid BookRoomDTO bookRoomDTO) HandlesPOSTrequests to/api/v1/reservationsand places a newReservationbased on the givenBookRoomDTO.@NonNull org.springframework.http.ResponseEntity<Void> deleteReservation(@Min(0L) Long id) HandlesDELETErequests to/api/v1/reservations/{id}and removes the requestingActor'sReservationwith the givenReservation.idfrom the database.@NonNull org.springframework.hateoas.EntityModel<ReservationDTO> getReservation(@NonNull Long id) HandlesGETrequests to/api/v1/reservations/{id}and fetches theReservationwith the specifiedReservation.idfrom the database, converts it to aReservationDTOobject and returns that.org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<ReservationSummaryDTO>> getReservations(int page, @Max(20L) int size, @NonNull String sortBy, boolean ascending) HandlesGETrequests to/api/v1/reservationsand retrieves a paginated subset of all Reservations by the requestingActoraccording to the URL parameters given.private @NonNull org.springframework.hateoas.EntityModel<ReservationSummaryDTO> reservationToSummaryDtoModel(@NonNull Reservation reservation)
-
Field Details
-
reservationService
Used to retrieve and save Reservations from the database. -
reservationMapper
Converts Reservations to data-transfer objects.
-
-
Constructor Details
-
ReservationRestController
public ReservationRestController(@NonNull @NonNull ReservationService reservationService, @NonNull @NonNull ReservationMapper reservationMapper) Creates a newReservationRestController.- Parameters:
reservationService- ThereservationService.reservationMapper- ThereservationMapper.
-
-
Method Details
-
getReservations
@GetMapping("/api/v1/reservations") public org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<ReservationSummaryDTO>> getReservations(@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) throws NotLoggedInException HandlesGETrequests to/api/v1/reservationsand retrieves a paginated subset of all Reservations by the requestingActoraccording 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 Reservations' 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.- Returns:
- The specified subset of all Reservations as summarised data-transfer objects.
- Throws:
NotLoggedInException- If the user is not authenticated.
-
getReservation
@GetMapping("/api/v1/reservations/{id}") @NonNull public @NonNull org.springframework.hateoas.EntityModel<ReservationDTO> getReservation(@NonNull @PathVariable @NonNull Long id) throws NotFoundException HandlesGETrequests to/api/v1/reservations/{id}and fetches theReservationwith the specifiedReservation.idfrom the database, converts it to aReservationDTOobject and returns that.- Parameters:
id- The ID of the Reservation that shall be returned.- Returns:
- The requested Reservation, represented as a data-transfer object.
- Throws:
NotFoundException- If there is no Reservation with the given ID.
-
bookRoom
@PostMapping("/api/v1/reservations") @PreAuthorize("hasRole('REGULAR')") @NonNull public @NonNull org.springframework.hateoas.EntityModel<ReservationDTO> bookRoom(@NonNull @Valid @RequestBody @NonNull @Valid BookRoomDTO bookRoomDTO) throws IllegalStateException, NotFoundException, TimeTravelException, ReversedTimePeriodException, ReservationPeriodTooSmallException, ReservationPeriodTooBigException, InvalidUseException, ConflictingReservationsException, de.gustavblass.commons.exceptions.IllegalArgumentException HandlesPOSTrequests to/api/v1/reservationsand places a newReservationbased on the givenBookRoomDTO.- Parameters:
bookRoomDTO- The data-transfer object representing the Reservation that shall be placed. Corresponds to the form input.- Returns:
- The successfully placed Reservation as a data-transfer object.
- Throws:
IllegalStateException- If the user cannot be authenticated for unknown reasons.NotFoundException- If theRoom.numberdoes not exist.TimeTravelException- If the reservation starts in the past.ReversedTimePeriodException- IfFilterReservationsDTO.fromdoes not come beforeFilterReservationsDTO.to.ReservationPeriodTooSmallException- IfFilterReservationsDTO.tocomes too shortly afterFilterReservationsDTO.from.ReservationPeriodTooBigException- If the period betweenFilterReservationsDTO.fromandFilterReservationsDTO.tois too long.ConflictingReservationsException- If there is already at least one Reservation for the Room in the specified time period.InvalidUseException- If theBookRoomDTO.useis not anIntendedUseenum value.de.gustavblass.commons.exceptions.IllegalArgumentException- If the Room,FilterReservationsDTO.date, start time, end time or intended use is not specified.
-
deleteReservation
@DeleteMapping("/api/v1/reservations/{id}") @NonNull public @NonNull org.springframework.http.ResponseEntity<Void> deleteReservation(@Min(0L) @PathVariable @Min(0L) Long id) throws NotFoundException HandlesDELETErequests to/api/v1/reservations/{id}and removes the requestingActor'sReservationwith the givenReservation.idfrom the database.- Parameters:
id- The identifier whose corresponding Reservation shall no longer be present in the system.- Returns:
- Empty response. Only the status code indicates success.
- Throws:
NotFoundException- If the requesting Actor has no Reservation with the given ID.
-
reservationToSummaryDtoModel
@NonNull private @NonNull org.springframework.hateoas.EntityModel<ReservationSummaryDTO> reservationToSummaryDtoModel(@NonNull @NonNull Reservation reservation) Converts a
Reservationto anEntityModelof aReservationSummaryDTO, with- the
getReservation(Long)method as anIanaLinkRelations.SELFlink, - the
RoomRestController.getRoom(String)method as link with the relationroom, - the
ActorRestController.getActor(String)method as link with the relationapplicant.
- Parameters:
reservation- The Reservation to be converted.- Returns:
- The converted Reservation.
- the
-