2021-06-24 12:36:16 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# public API controller for resources of type Reservation
|
2016-05-04 18:17:50 +02:00
|
|
|
class OpenAPI::V1::ReservationsController < OpenAPI::V1::BaseController
|
2016-05-05 15:02:02 +02:00
|
|
|
extend OpenAPI::ApiDoc
|
2021-06-24 12:36:16 +02:00
|
|
|
include Rails::Pagination
|
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)
|
2021-06-24 12:36:16 +02:00
|
|
|
.includes(statistic_profile: :user)
|
|
|
|
.references(:statistic_profiles)
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2021-06-28 10:17:26 +02:00
|
|
|
@reservations = @reservations.where(statistic_profiles: { user_id: params[:user_id] }) if params[:user_id].present?
|
2021-06-24 12:36:16 +02:00
|
|
|
@reservations = @reservations.where(reservable_type: format_type(params[:reservable_type])) if params[:reservable_type].present?
|
|
|
|
@reservations = @reservations.where(reservable_id: params[:reservable_id]) if params[:reservable_id].present?
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2021-06-24 12:36:16 +02:00
|
|
|
return unless params[:page].present?
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2021-06-24 12:36:16 +02:00
|
|
|
@reservations = @reservations.page(params[:page]).per(per_page)
|
|
|
|
paginate @reservations, per_page: per_page
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-06-24 12:36:16 +02:00
|
|
|
def format_type(type)
|
|
|
|
type.singularize.classify
|
|
|
|
end
|
|
|
|
|
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|