1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/controllers/open_api/v1/reservations_controller.rb
2023-03-06 16:35:50 +01:00

37 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require_relative 'concerns/reservations_filters_concern'
# public API controller for resources of type Reservation
class OpenAPI::V1::ReservationsController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc
include Rails::Pagination
include ReservationsFiltersConcern
expose_doc
def index
@reservations = Reservation.order(created_at: :desc)
.includes(slots_reservations: :slot, statistic_profile: :user)
.references(:statistic_profiles)
@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)
@reservations = @reservations.page(page).per(per_page)
paginate @reservations, per_page: per_page
end
private
def page
params[:page] || 1
end
def per_page
params[:per_page] || 20
end
end