1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-13 23:48:55 +01:00
fab-manager/app/controllers/open_api/v1/reservations_controller.rb

37 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2023-03-06 16:35:50 +01:00
require_relative 'concerns/reservations_filters_concern'
# 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
include Rails::Pagination
2023-03-06 16:35:50 +01:00
include 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)
.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)
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
def per_page
params[:per_page] || 20
end
2016-05-04 18:17:50 +02:00
end