1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

open api events improvement

new data available: start_at, end_at, event_image
new controllers: id, upcoming, limit
This commit is contained in:
siteswapjuggler 2017-09-03 13:55:38 +02:00
parent 8a4d9dd45b
commit 73c9e301fb
3 changed files with 29 additions and 1 deletions

View File

@ -3,16 +3,34 @@ class OpenAPI::V1::EventsController < OpenAPI::V1::BaseController
expose_doc
def index
@events = Event.order(created_at: :desc)
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
if params[:limit].present?
@events = @events.limit(params[:limit])
end
end
private
def per_page
params[:per_page] || 20
end
def upcoming
params[:upcoming] || false
end
end

View File

@ -11,6 +11,9 @@ class OpenAPI::V1::EventsDoc < OpenAPI::V1::BaseDoc
doc_for :index do
api :GET, "/#{API_VERSION}/events", "Events index"
param_group :pagination
param :id, [Integer, Array], optional: true, desc: "Scope the request to one or various events."
param :upcoming, [FalseClass, TrueClass], optional: true, desc: "Scope for the upcoming events."
param :limit, [Integer], optional: true, desc: "Limits the number of events."
description "Events index. Order by *created_at* desc."
example <<-EOS
# /open_api/v1/events?page=1&per_page=2

View File

@ -1,6 +1,13 @@
json.events @events do |event|
json.partial! 'open_api/v1/events/event', event: event
json.extract! event, :nb_total_places, :nb_free_places
json.start_at event.availability.start_at
json.end_at event.availability.end_at
json.event_image do
json.large_url root_url + event.event_image.attachment.large.url
json.medium_url root_url + event.event_image.attachment.medium.url
json.small_url root_url + event.event_image.attachment.small.url
end
json.prices do
json.normal do
json.name I18n.t('app.public.home.full_price')