courses_controller.rb 652 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2
# Contains all actions having to do with Courses.
class CoursesController < ApplicationController
3
  # Renders JSON of courses matching params.
Zac Wood's avatar
Zac Wood committed
4 5
  def index
    @courses = Course.all
6

7
    # filter by subject + course number if the params are included
8 9
    @courses = @courses.where(subject: params[:subject].upcase) if params.key?(:subject)
    @courses = @courses.where(course_number: params[:course_number]) if params.key?(:course_number)
10

Zac Wood's avatar
Zac Wood committed
11 12
    render json: @courses
  end
13 14 15 16 17 18 19

  # Renders JSON of details of a singluar course, such as its sections
  def show
    @sections = CourseSection.where(course_id: params[:id])

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