course_listings_controller.rb 660 Bytes
Newer Older
1
class CourseListingsController < ApplicationController
2 3 4
  resource_description do
    short 'Working with courses and associated sections'
  end
Zach Perkins's avatar
Zach Perkins committed
5

6
  api :GET, '/course_listings', "Get all available courses and their sections"
Zach Perkins's avatar
Zach Perkins committed
7
  param :subject, String, desc: 'Course subject, e.g. "CS" or "ACCT"'
8 9
  param :number, Integer, desc: 'Course number, e.g. "112"'
  def index
Zach Perkins's avatar
Zach Perkins committed
10 11
    # Make a separate list so that we can include sections
    @courses = []
12
    Course.fetch(params).all.each do |course_obj|
Zach Perkins's avatar
Zach Perkins committed
13 14 15 16 17 18
      course = course_obj.attributes.dup
      course[:sections] = course_obj.course_sections
      @courses.push(course)
    end

    render json: @courses
19
  end
20
end