Class ReservationAdminRestController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.ReservationAdminRestController
Defines the behaviour of the API server for the path
/api/v1/admin/reservations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumPre-compiled UriTemplates for HATEOAS-compliant API responses. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @NonNull ReservationMapperConverts Reservations to data-transfer objects.private final ReservationServiceUsed to retrieve and save Reservations from the database.private final Function<Reservation, org.springframework.hateoas.EntityModel<ReservationSummaryDTO>> -
Constructor Summary
ConstructorsConstructorDescriptionReservationAdminRestController(@NonNull ReservationService reservationService, @NonNull ReservationMapper reservationMapper) Constructs a newReservationAdminRestControllerwith the givenreservationService. -
Method Summary
Modifier and TypeMethodDescription@NonNull org.springframework.http.ResponseEntity<Void> deleteReservation(@Min(0L) Long id) HandlesDELETErequests to/api/v1/admin/reservations/{id}and removes theReservationwith the givenReservation.idfrom the database.@NonNull org.springframework.http.ResponseEntity<Void> deleteReservation(@NonNull ArrayList<Long> ids) HandlesDELETErequests to/api/v1/admin/reservationsand mass-removes all Reservations with the given IDs from the database.@NonNull org.springframework.hateoas.EntityModel<ReservationDTO> getReservation(@NonNull Long id) HandlesGETrequests to/api/v1/admin/reservations/{id}and fetches theReservationwith the specifiedReservation.idfrom the database, converts it to anReservationDTOobject and returns that.org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<ReservationSummaryDTO>> getReservations(int page, @Max(20L) int size, @NonNull String sortBy, boolean ascending) Retrieves a paginated subset of all Reservations according to the URL parameters given.org.springframework.hateoas.CollectionModel<org.springframework.hateoas.EntityModel<ReservationSummaryDTO>> getReservations(int page, @Max(20L) int size, @NonNull String sortBy, boolean ascending, @Nullable FilterReservationsDTO filterReservationsDTO) HandlesGETrequests to/api/v1/admin/reservations.
-
Field Details
-
reservationToSummaryDtoModel
private final Function<Reservation, org.springframework.hateoas.EntityModel<ReservationSummaryDTO>> reservationToSummaryDtoModelConverts 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.
- the
-
reservationService
Used to retrieve and save Reservations from the database. -
reservationMapper
Converts Reservations to data-transfer objects.
-
-
Constructor Details
-
ReservationAdminRestController
public ReservationAdminRestController(@NonNull @NonNull ReservationService reservationService, @NonNull @NonNull ReservationMapper reservationMapper) Constructs a newReservationAdminRestControllerwith the givenreservationService.- Parameters:
reservationService- ThereservationServiceto use for database access.reservationMapper- ThereservationMapperto convert Reservations to data-transfer objects.
-
-
Method Details
-
getReservations
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) Retrieves a paginated subset of all Reservations according 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.
- Implementation Note:
- Does not handle HTTP requests, but serves as a fallback for
getReservations(int, int, String, boolean, FilterReservationsDTO).
-
getReservations
@GetMapping("/api/v1/admin/reservations") public org.springframework.hateoas.CollectionModel<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, @Nullable @Nullable FilterReservationsDTO filterReservationsDTO) throws NotFoundException, de.gustavblass.commons.exceptions.IllegalArgumentException Handles
GETrequests to/api/v1/admin/reservations. Retrieves a paginated or filtered subset of all Reservations according to the URL parameters given.The paging parameters
page,size,sortByandascendingare ignored if any of the filtering parameters is set (roomNumber,dateString,startTimeString,endTimeString).- 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.filterReservationsDTO- Filtering parameters indicating what criteria the requested Reservations must fulfil.- Returns:
- The specified subset of all Reservations as summarised data-transfer objects.
- Throws:
NotFoundException- When the user requests the Reservations for an inexistentRoom.number.de.gustavblass.commons.exceptions.IllegalArgumentException- If the start time is not before the end time.
-
getReservation
@GetMapping("/api/v1/admin/reservations/{id}") @NonNull public @NonNull org.springframework.hateoas.EntityModel<ReservationDTO> getReservation(@NonNull @PathVariable @NonNull Long id) throws NotFoundException HandlesGETrequests to/api/v1/admin/reservations/{id}and fetches theReservationwith the specifiedReservation.idfrom the database, converts it to anReservationDTOobject 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.
-
deleteReservation
@DeleteMapping("/api/v1/admin/reservations/{id}") @NonNull public @NonNull org.springframework.http.ResponseEntity<Void> deleteReservation(@Min(0L) @PathVariable @Min(0L) Long id) throws NotFoundException HandlesDELETErequests to/api/v1/admin/reservations/{id}and removes theReservationwith 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 no Reservation with the given ID exists.
-
deleteReservation
@DeleteMapping("/api/v1/admin/reservations") @NonNull public @NonNull org.springframework.http.ResponseEntity<Void> deleteReservation(@NonNull @RequestParam(name="id") @NonNull ArrayList<Long> ids) throws NotFoundException HandlesDELETErequests to/api/v1/admin/reservationsand mass-removes all Reservations with the given IDs from the database.- Parameters:
ids- The identifiers of the Reservations that shall no longer be stored.- Returns:
- Empty response. Only the status code indicates success.
- Throws:
NotFoundException- If at least one ID does not exist. Then, no Reservation is deleted.
-