mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
a55880a0ad
Also: (bug) filter by array in openAPI = error
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# public API controller for resources of type Reservation
|
|
class OpenAPI::V1::ReservationsController < OpenAPI::V1::BaseController
|
|
extend OpenAPI::ApiDoc
|
|
include Rails::Pagination
|
|
expose_doc
|
|
|
|
def index
|
|
@reservations = Reservation.order(created_at: :desc)
|
|
.includes(statistic_profile: :user)
|
|
.references(:statistic_profiles)
|
|
|
|
@reservations = @reservations.where(statistic_profiles: { user_id: may_array(params[:user_id]) }) if params[:user_id].present?
|
|
@reservations = @reservations.where(reservable_type: format_type(params[:reservable_type])) if params[:reservable_type].present?
|
|
@reservations = @reservations.where(reservable_id: may_array(params[:reservable_id])) if params[:reservable_id].present?
|
|
|
|
return if params[:page].blank?
|
|
|
|
@reservations = @reservations.page(params[:page]).per(per_page)
|
|
paginate @reservations, per_page: per_page
|
|
end
|
|
|
|
private
|
|
|
|
def format_type(type)
|
|
type.singularize.classify
|
|
end
|
|
|
|
def per_page
|
|
params[:per_page] || 20
|
|
end
|
|
end
|