Add a json export of the schedule
This commit is contained in:
parent
26e523dc2f
commit
b5cd1ff8f1
|
@ -0,0 +1,25 @@
|
|||
class Schedule
|
||||
include ActiveModel::Model
|
||||
attr_accessor :hall, :slots
|
||||
|
||||
def self.for_conference(conference)
|
||||
schedule = {}
|
||||
conference.halls.each do |hall|
|
||||
schedule[hall.id] = hall.slots.includes(:event, event: [:speakers]).where('starts_at < ?', Date.tomorrow).where.not(event_id: nil).order(:starts_at).map do |slot|
|
||||
{
|
||||
title: slot.event.title,
|
||||
subtitle: slot.event.subtitle,
|
||||
startTime: slot.starts_at,
|
||||
endTime: slot.ends_at,
|
||||
speakers: slot.event.speakers.map do |speaker|
|
||||
{
|
||||
name: speaker.name,
|
||||
description: speaker.biography
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
schedule
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class SchedulesController < ApplicationController
|
||||
def show
|
||||
@schedule = Schedule.for_conference Conference.current
|
||||
headers['Access-Control-Allow-Origin'] = '*'
|
||||
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
|
||||
headers['Access-Control-Max-Age'] = "1728000"
|
||||
|
||||
respond_to { |format| format.json { render json: @schedule.to_json } }
|
||||
end
|
||||
end
|
|
@ -11,6 +11,7 @@ class Conference < ActiveRecord::Base
|
|||
has_many :tracks, -> { order('id asc') }
|
||||
has_many :events, through: :tracks
|
||||
has_many :candidate_speakers, through: :events
|
||||
has_many :halls
|
||||
|
||||
scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') }
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
class Hall < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
has_many :slots
|
||||
end
|
||||
|
|
|
@ -11,6 +11,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resource :schedule, only: [:show]
|
||||
|
||||
devise_for :users, controllers: {registrations: 'registrations', sessions: 'sessions'}
|
||||
|
||||
namespace :management do
|
||||
|
|
Loading…
Reference in New Issue