2016-05-04 18:17:50 +02:00
|
|
|
class OpenAPI::V1::EventsController < OpenAPI::V1::BaseController
|
2016-05-05 15:02:02 +02:00
|
|
|
extend OpenAPI::ApiDoc
|
|
|
|
expose_doc
|
|
|
|
|
2016-05-04 18:17:50 +02:00
|
|
|
def index
|
2017-09-03 13:55:38 +02:00
|
|
|
|
|
|
|
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
|
2016-05-04 18:17:50 +02:00
|
|
|
|
|
|
|
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
|
2017-09-03 13:55:38 +02:00
|
|
|
def upcoming
|
|
|
|
params[:upcoming] || false
|
|
|
|
end
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|