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/events_controller.rb
siteswapjuggler cda13540f9 limit parameter removed
as requested
2017-09-24 18:39:32 +02:00

33 lines
826 B
Ruby

class OpenAPI::V1::EventsController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc
expose_doc
def index
if upcoming
@events = Event.includes(:event_image, :event_files, :availability, :category)
.where('availabilities.end_at >= ?', Time.now)
.order('availabilities.start_at ASC').references(:availabilities)
else
@events = Event.includes(:event_image, :event_files, :availability, :category).order(created_at: :desc)
end
if params[:id].present?
@events = @events.where(id: params[:id])
end
if params[:page].present?
@events = @events.page(params[:page]).per(per_page)
paginate @events, per_page: per_page
end
end
private
def per_page
params[:per_page] || 20
end
def upcoming
params[:upcoming] || false
end
end