2021-06-24 12:36:16 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-03-06 16:35:50 +01:00
|
|
|
require_relative 'concerns/reservations_filters_concern'
|
|
|
|
|
2021-06-24 12:36:16 +02:00
|
|
|
# public API controller for resources of type Reservation
|
2016-05-04 18:17:50 +02:00
|
|
|
class OpenAPI::V1::ReservationsController < OpenAPI::V1::BaseController
|
2023-02-24 17:26:55 +01:00
|
|
|
extend OpenAPI::APIDoc
|
2021-06-24 12:36:16 +02:00
|
|
|
include Rails::Pagination
|
2023-02-24 17:26:55 +01:00
|
|
|
include OpenAPI::V1::Concerns::ReservationsFiltersConcern
|
2016-05-05 15:02:02 +02:00
|
|
|
expose_doc
|
|
|
|
|
2016-05-04 18:17:50 +02:00
|
|
|
def index
|
|
|
|
@reservations = Reservation.order(created_at: :desc)
|
2023-03-03 10:09:07 +01:00
|
|
|
.includes(slots_reservations: :slot, statistic_profile: :user)
|
2021-06-24 12:36:16 +02:00
|
|
|
.references(:statistic_profiles)
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2023-03-06 16:35:50 +01:00
|
|
|
@reservations = filter_by_after(@reservations, params)
|
|
|
|
@reservations = filter_by_before(@reservations, params)
|
|
|
|
@reservations = filter_by_user(@reservations, params)
|
|
|
|
@reservations = filter_by_reservable_type(@reservations, params)
|
|
|
|
@reservations = filter_by_reservable_id(@reservations, params)
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2023-03-03 10:09:07 +01:00
|
|
|
@reservations = @reservations.page(page).per(per_page)
|
2021-06-24 12:36:16 +02:00
|
|
|
paginate @reservations, per_page: per_page
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-03-03 10:09:07 +01:00
|
|
|
def page
|
|
|
|
params[:page] || 1
|
|
|
|
end
|
|
|
|
|
2021-06-24 12:36:16 +02:00
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|