courses_controller.rb 959 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2
# Contains all actions having to do with Courses.
class CoursesController < ApplicationController
Zac Wood's avatar
Zac Wood committed
3 4 5 6 7 8
  resource_description do
      short 'Working with courses, e.g. CS 112'
  end
  
  api :GET, '/courses', "Get a list of courses."
  param :subject, String, desc: 'Course subject, e.g. "CS" or "ACCT"'
Zac Wood's avatar
Zac Wood committed
9
  param :course_number, Integer, desc: 'Course number, e.g. "112"'
Zac Wood's avatar
Zac Wood committed
10 11
  def index
    @courses = Course.all
12

13
    # filter by subject + course number if the params are included
14 15
    @courses = @courses.where(subject: params[:subject].upcase) if params.key?(:subject)
    @courses = @courses.where(course_number: params[:course_number]) if params.key?(:course_number)
16

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

Zac Wood's avatar
Zac Wood committed
20 21
  api :GET, '/courses/:id', "Get a list of all course sections for the course with the given id."
  param :id, :number, desc: 'Course ID', required: true
22 23 24 25 26
  def show
    @sections = CourseSection.where(course_id: params[:id])

    render json: @sections
  end
Zac Wood's avatar
Zac Wood committed
27
end