diff --git a/app/controllers/schedule.rb b/app/controllers/schedule.rb new file mode 100644 index 0000000..3a0f3f2 --- /dev/null +++ b/app/controllers/schedule.rb @@ -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 diff --git a/app/controllers/schedules_controller.rb b/app/controllers/schedules_controller.rb new file mode 100644 index 0000000..564a93e --- /dev/null +++ b/app/controllers/schedules_controller.rb @@ -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 diff --git a/app/models/conference.rb b/app/models/conference.rb index 224a408..7d9955f 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -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') } diff --git a/app/models/hall.rb b/app/models/hall.rb index 9661672..22cb339 100644 --- a/app/models/hall.rb +++ b/app/models/hall.rb @@ -1,3 +1,4 @@ class Hall < ActiveRecord::Base belongs_to :conference + has_many :slots end diff --git a/config/routes.rb b/config/routes.rb index 636156f..b4cb7f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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