2021-06-24 12:36:16 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# authorized 3rd party softwares can manage the events through the OpenAPI
|
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
|
2021-06-24 12:36:16 +02:00
|
|
|
include Rails::Pagination
|
2016-05-05 15:02:02 +02:00
|
|
|
expose_doc
|
2021-06-24 12:36:16 +02:00
|
|
|
|
2016-05-04 18:17:50 +02:00
|
|
|
def index
|
2021-06-24 12:36:16 +02:00
|
|
|
@events = Event.includes(:event_image, :event_files, :availability, :category)
|
2023-01-19 17:41:21 +01:00
|
|
|
.where(deleted_at: nil)
|
2021-06-24 12:36:16 +02:00
|
|
|
@events = if upcoming
|
|
|
|
@events.references(:availabilities)
|
2023-02-14 13:10:58 +01:00
|
|
|
.where('availabilities.end_at >= ?', Time.current)
|
2021-06-24 12:36:16 +02:00
|
|
|
.order('availabilities.start_at ASC')
|
|
|
|
else
|
|
|
|
@events.order(created_at: :desc)
|
|
|
|
end
|
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
@events = @events.where(id: may_array(params[:id])) if params[:id].present?
|
2021-06-24 12:36:16 +02:00
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
return if params[:page].blank?
|
2021-06-24 12:36:16 +02:00
|
|
|
|
|
|
|
@events = @events.page(params[:page]).per(per_page)
|
|
|
|
paginate @events, per_page: per_page
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2021-06-24 12:36:16 +02:00
|
|
|
|
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
|
|
|
|
|
|
|
def upcoming
|
|
|
|
params[:upcoming] || false
|
|
|
|
end
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|