Class RoomRestController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.RoomRestController
Defines the behaviour of the API server for the path
/api/v1/rooms.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumPre-compiled UriTemplates for HATEOAS-compliant API responses. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RoomMapperprivate final RoomServiceUsed to retrieve and save Rooms from the database. -
Constructor Summary
ConstructorsConstructorDescriptionRoomRestController(@NonNull RoomService roomService, @NonNull RoomMapper roomMapper) Constructs a newRoomRestControllerwith the givenroomService. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.hateoas.EntityModel<RoomDTO> HandlesGETrequests to/api/v1/rooms/{number}.org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<RoomSummaryDTO>> HandlesGETrequests to/api/v1/rooms.org.springframework.hateoas.EntityModel<RoomSchedule> getRoomSchedule(@NonNull String number, @Nullable LocalDate date, @Nullable LocalTime startTime, @Nullable LocalTime endTime) HandlesGETrequests to/api/v1/rooms/{number}/scheduleand returns today'sRoomSchedulefor theRoomwith the givenRoom.number.
-
Field Details
-
roomService
Used to retrieve and save Rooms from the database. -
roomMapper
-
-
Constructor Details
-
RoomRestController
public RoomRestController(@NonNull @NonNull RoomService roomService, @NonNull @NonNull RoomMapper roomMapper) Constructs a newRoomRestControllerwith the givenroomService.- Parameters:
roomService- TheroomServiceto use for database access.roomMapper- TheroomMapperfor conversion to/from data-transfer objects.
-
-
Method Details
-
getRooms
@GetMapping("/api/v1/rooms") public org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<RoomSummaryDTO>> 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) HandlesGETrequests to/api/v1/rooms. Retrieves a paginated subset of all Rooms according to the URL parameters given.- Parameters:
page- The index of the page requested.size- How many Rooms items each page in the pagination has.sortBy- Which of the Rooms' 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 Rooms as summarised data-transfer objects.
-
getRoom
@GetMapping("/api/v1/rooms/{number}") public org.springframework.hateoas.EntityModel<RoomDTO> getRoom(@NonNull @PathVariable @NonNull String number) throws NotFoundException HandlesGETrequests to/api/v1/rooms/{number}. Retrieves a specificRoomdenoted by the path parameternumberand converts it to a data-transfer object.- Parameters:
number- The path parameter{number}denoting a specific Room.- Returns:
- The requested Room as a DTO.
- Throws:
NotFoundException- If no Room with the given number exists.
-
getRoomSchedule
@GetMapping("/api/v1/rooms/{number}/schedule") public org.springframework.hateoas.EntityModel<RoomSchedule> getRoomSchedule(@NonNull @PathVariable @NonNull String number, @Nullable @RequestParam(value="date",required=false) @Nullable LocalDate date, @Nullable @RequestParam(value="from",required=false) @Nullable LocalTime startTime, @Nullable @RequestParam(value="to",required=false) @Nullable LocalTime endTime) throws NotFoundException, ReversedTimePeriodException, ReservationPeriodTooSmallException HandlesGETrequests to/api/v1/rooms/{number}/scheduleand returns today'sRoomSchedulefor theRoomwith the givenRoom.number.- Parameters:
number- The number of the Room whose schedule shall be returned.date- TheLocalDatefor which the schedule shall be generated.startTime- Ignore Reservations that come before this point in time. Must come >5 minutes before theendTime!endTime- Ignore Reservations that come after this point in time. Must come >5 minutes after thestartTime!- Returns:
- The Room's schedule.
- Throws:
NotFoundException- If no Room with the given number exists.ReversedTimePeriodException- If the start time does not come before the end time.ReservationPeriodTooSmallException- If thestartTimedoes not come >5 minutes before theendTime.
-