courses_controller.rb 721 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1
# Contains all actions having to do with Courses.
Zac Wood's avatar
Zac Wood committed
2
class API::CoursesController < ApplicationController
Zac Wood's avatar
Zac Wood committed
3
  resource_description do
Zac Wood's avatar
Zac Wood committed
4
    short 'Working with courses, e.g. CS 112'
Zac Wood's avatar
Zac Wood committed
5
  end
Zac Wood's avatar
Zac Wood committed
6

Zac Wood's avatar
Zac Wood committed
7 8
  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
  def index 
11
    @courses = Course.fetch(params).all
Zac Wood's avatar
Zac Wood committed
12 13
    render json: @courses
  end
14

Zac Wood's avatar
Zac Wood committed
15 16
  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
17
  def show
Zach Perkins's avatar
Zach Perkins committed
18
    @sections = CourseSection.where(course_id: params[:id]).all
19 20 21

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