course_sections_controller.rb 881 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
  resource_description do
Zac Wood's avatar
Zac Wood committed
5
    short 'Working with course sections, e.g. CS 112 001'
Zac Wood's avatar
Zac Wood committed
6
  end
Zac Wood's avatar
Zac Wood committed
7

Zac Wood's avatar
Zac Wood committed
8
  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"
11
  param :instructor, String, desc: "Get course sections being taught by this instructor"
Zac Wood's avatar
Zac Wood committed
12
  def index
13
    @sections = CourseSection.with_instructor(name: params[:instructor])
14 15 16

    @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
17

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