Class RoomRestController

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.RoomRestController

@RestController public class RoomRestController extends Object
Defines the behaviour of the API server for the path /api/v1/rooms.
  • Field Details

    • roomService

      private final RoomService roomService
      Used to retrieve and save Rooms from the database.
    • roomMapper

      private final RoomMapper roomMapper
      Used to convert Room objects to RoomDTO objects when returning them to the user.
  • Constructor Details

  • 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)
      Handles GET requests 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 using sortBy.
      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
      Handles GET requests to /api/v1/rooms/{number}. Retrieves a specific Room denoted by the path parameter number and 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
      Handles GET requests to /api/v1/rooms/{number}/schedule and returns today's RoomSchedule for the Room with the given Room.number.
      Parameters:
      number - The number of the Room whose schedule shall be returned.
      date - The LocalDate for which the schedule shall be generated.
      startTime - Ignore Reservations that come before this point in time. Must come >5 minutes before the endTime!
      endTime - Ignore Reservations that come after this point in time. Must come >5 minutes after the startTime!
      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 the startTime does not come >5 minutes before the endTime.