schedules_controller.rb 1.08 KB
Newer Older
1 2
# Contains functionality for generating schedules.
class SchedulesController < ApplicationController
3 4 5
  resource_description do
    short 'Endpoints for generating iCal files'
  end
Zac Wood's avatar
Zac Wood committed
6
  # Render an iCal file containing the schedules of all the
7
  # course sections with the given CRNs.
8
  api :GET, '/schedules', 'Generate an iCal file with events for the given CRNs'
Zac Wood's avatar
Zac Wood committed
9
  param :crns, String, desc: 'Comma separated list of CRNs to include as events in the calendar', required: true
10 11 12 13 14
  def index
    crns = params["crns"].split ','
    @schedule = Schedule.new crns
    render plain: @schedule.to_ical # render a plaintext iCal file
  end
Zac Wood's avatar
Zac Wood committed
15

16
  include SchedulesHelper
Zac Wood's avatar
Zac Wood committed
17
  def show
18 19 20 21 22 23
    combined = {}
    @cart.each do |cid, sections|
      combined[cid] = []
      sections.each do |section|

      end
Zac Wood's avatar
Zac Wood committed
24 25
    end

26 27 28
    courses = @cart.values.group_by do |s|
      s.course.id
    end
Zac Wood's avatar
Zac Wood committed
29

30 31 32 33
    puts courses.keys
    
    id_sets = generate_schedules(@cart.values)
    @events = generate_fullcalender_events(id_sets)
Zac Wood's avatar
Zac Wood committed
34
  end
35 36 37 38

  # this works(?)
  # recursively build a list of sets containing 1 section from each course chosen

39
end