Commit 82096fc8 authored by Zach Perkins's avatar Zach Perkins
Browse files

Merge branch '24-course-listing-endpoint' of...

Merge branch '24-course-listing-endpoint' of into 26-model-filters
parents fc66554a 091006ce
...@@ -4,8 +4,9 @@ Rails.application.routes.draw do ...@@ -4,8 +4,9 @@ Rails.application.routes.draw do
get 'search/update', to: 'search#update' get 'search/update', to: 'search#update'
scope :api do # Register /api routes scope :api do # Register /api routes
resources :courses, only: [:index, :show] resources :courses, only: [:index, :show, :listing]
resources :course_sections, only: [:index] resources :course_sections, only: [:index]
resources :course_listing, only: [:index]
resources :schedules, only: [:index] resources :schedules, only: [:index]
end end
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
// Place all the styles related to the CourseListing controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here:
class CourseListingController < ApplicationController
resource_description do
short 'Working with courses and associated sections'
api :GET, '/course_listing', "Get all available courses and their sections"
param :subject, String, desc: 'Course subject, e.g. "CS" or "ACCT"'
param :number, Integer, desc: 'Course number, e.g. "112"'
def index
db_params = {}
# Grab all of the params we pass to the query from the GET arguments
params.each do |name, value|
db_params[name.to_sym] = value if Course.column_names.include? name
# Make a separate list so that we can include sections
@courses = []
Course.where(db_params).all.each do |course_obj|
course = course_obj.attributes.dup
course[:sections] = course_obj.course_sections
render json: @courses
require 'test_helper'
class CourseListingControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment