Commit 92536944 authored by Zach Perkins's avatar Zach Perkins
Browse files

Got the a successful course listing

parent 1dba6b23
......@@ -3,7 +3,19 @@ class CourseListingController < ApplicationController
param :subject, String, desc:'Course subject, e.g. "CS" or "ACCT"'
param :number, Integer, desc: 'Course number, e.g. "112"'
def index
@courses = Course.find_by(params).joins('sections')
db_params = {}
params.each do |name, value|
db_params[:subject] = value if name == "subject"
db_params[:course_number] = value if name == "number"
db_courses = Course.where(db_params).all
@courses = []
db_courses.each do |course|
c = course.attributes.dup
c[:sections] = CourseSection.where(course_id:
render json: @courses
......@@ -3,6 +3,7 @@ Rails.application.routes.draw do
scope :api do # Register /api routes
resources :courses, only: [:index, :show]
resources :course_sections, only: [:index]
resources :course_listing, only: [:index]
resources :schedules, only: [:index]
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