Add a simple JSON API
This commit is contained in:
parent
82d44e79a7
commit
bf278693b3
|
@ -0,0 +1,8 @@
|
||||||
|
class Api::EventTypesController < Api::ApplicationController
|
||||||
|
include ::CurrentConferenceAssigning
|
||||||
|
before_filter :require_current_conference!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@event_types = current_conference.event_types.includes(:translations)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Api::HallsController < Api::ApplicationController
|
||||||
|
include ::CurrentConferenceAssigning
|
||||||
|
before_filter :require_current_conference!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@halls = current_conference.halls
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Api::SlotsController < Api::ApplicationController
|
||||||
|
include ::CurrentConferenceAssigning
|
||||||
|
before_filter :require_current_conference!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@slots = current_conference.slots
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Api::SpeakersController < Api::ApplicationController
|
||||||
|
include ::CurrentConferenceAssigning
|
||||||
|
before_filter :require_current_conference!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@speakers = PersonalProfile.joins(user: [:events]).where(conference: current_conference)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Api::TracksController < Api::ApplicationController
|
||||||
|
include ::CurrentConferenceAssigning
|
||||||
|
before_filter :require_current_conference!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@tracks = current_conference.tracks.includes(:translations)
|
||||||
|
end
|
||||||
|
end
|
|
@ -15,6 +15,7 @@ class Conference < ActiveRecord::Base
|
||||||
has_many :volunteer_teams
|
has_many :volunteer_teams
|
||||||
has_one :call_for_participation, dependent: :destroy
|
has_one :call_for_participation, dependent: :destroy
|
||||||
has_many :participants, class_name: 'User', through: :events
|
has_many :participants, class_name: 'User', through: :events
|
||||||
|
has_many :slots, through: :events
|
||||||
|
|
||||||
accepts_nested_attributes_for :tracks, :halls, :event_types, :volunteer_teams,
|
accepts_nested_attributes_for :tracks, :halls, :event_types, :volunteer_teams,
|
||||||
reject_if: :all_blank, allow_destroy: true
|
reject_if: :all_blank, allow_destroy: true
|
||||||
|
|
|
@ -3,6 +3,7 @@ class Event < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
belongs_to :track
|
belongs_to :track
|
||||||
|
has_one :slot
|
||||||
|
|
||||||
has_many :participations, dependent: :destroy
|
has_many :participations, dependent: :destroy
|
||||||
has_many :pending_participations, ->() { pending }, class_name: 'Participation'
|
has_many :pending_participations, ->() { pending }, class_name: 'Participation'
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
json.array! @event_types do |event_type|
|
||||||
|
json.extract! event_type, :id
|
||||||
|
json.name do
|
||||||
|
event_type.translations.each do |translation|
|
||||||
|
json.set! translation.locale, translation.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
json.description do
|
||||||
|
event_type.translations.each do |translation|
|
||||||
|
json.set! translation.locale, translation.description
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1 @@
|
||||||
|
json.array! @halls, :id, :name
|
|
@ -0,0 +1 @@
|
||||||
|
json.array! @slots, :hall_id, :event_id, :starts_at, :ends_at
|
|
@ -0,0 +1,4 @@
|
||||||
|
json.array! @speakers do |speaker|
|
||||||
|
json.extract! speaker, :user_id, :twitter, :github, :biography, :public_email, :organisation, :last_name, :first_name
|
||||||
|
json.picture speaker.picture.serializable_hash
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
json.array! @tracks do |track|
|
||||||
|
json.extract! track, :id
|
||||||
|
json.name do
|
||||||
|
track.translations.each do |translation|
|
||||||
|
json.set! translation.locale, translation.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
json.description do
|
||||||
|
track.translations.each do |translation|
|
||||||
|
json.set! translation.locale, translation.description
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -14,6 +14,11 @@ Rails.application.routes.draw do
|
||||||
namespace :api do
|
namespace :api do
|
||||||
resources :conferences, only: [] do
|
resources :conferences, only: [] do
|
||||||
resources :events, only: :index
|
resources :events, only: :index
|
||||||
|
resources :speakers, only: :index
|
||||||
|
resources :tracks, only: :index
|
||||||
|
resources :event_types, only: :index
|
||||||
|
resources :halls, only: :index
|
||||||
|
resources :slots, only: :index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue