course_sections_controller.rb 757 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1
# Contains all actions having to do with CourseSections.
Zac Wood's avatar
Zac Wood committed
2
# This is a nested controller -- see +config/routes.rb+ for details
Zac Wood's avatar
Zac Wood committed
3
class CourseSectionsController < ApplicationController
Zac Wood's avatar
Zac Wood committed
4 5 6 7 8
  resource_description do
      short 'Working with course sections, e.g. CS 112 001'
  end
  
  api :GET, '/courses_sections', 'Get a list of course sections'
Zac Wood's avatar
Zac Wood committed
9
  param :course_id, Integer, desc: "Only get the course sections belonging to the course with this ID"
Zac Wood's avatar
Zac Wood committed
10
  param :crn, String, desc: "Get the course section with this CRN"
Zac Wood's avatar
Zac Wood committed
11
  def index
12 13 14 15
    @sections = CourseSection.all

    @sections = @sections.where(course_id: params[:course_id]) if params.key?(:course_id)
    @sections = @sections.where(crn: params[:crn]) if params.key?(:crn)
Zac Wood's avatar
Zac Wood committed
16

Zac Wood's avatar
Zac Wood committed
17 18 19
    render json: @sections
  end
end