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

Fixed the booboos

parent fe2dd688
Pipeline #2954 passed with stage
in 2 minutes and 12 seconds
......@@ -15,7 +15,7 @@ class CoursesController < ApplicationController
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
def show
@sections = CourseSection.fetch(params).all
@sections = CourseSection.where(course_id: params[:id]).all
render json: @sections
end
......
......@@ -22,12 +22,12 @@ class Course < ApplicationRecord
end
def self.from_course_number(base_query, course_number)
query = base_query.where("courses.course_number = ?", course_number)
base_query.where("courses.course_number = ?", course_number)
end
def self.from_title(base_query, title)
# Temporary really disgusting regex that I hate with all my heart
title = (title + " ").gsub(" 1", " I").gsub(" 2", " II").gsub(" 3", " III").upcase.gsub(/(I+) +/, '\1$').gsub(/ +/, "% ").gsub('$', ' ')
title = (title + " ").gsub(" 1", " I").gsub(" 2", " II").gsub(" 3", " III").upcase.gsub(/(I+) +/, '\1$').gsub(/ +/, "% ").tr('$', ' ')
base_query.where("UPPER(courses.title) LIKE UPPER(?) or UPPER(courses.title) LIKE UPPER(?)", "%#{title.strip}", "%#{title}%")
end
......@@ -60,9 +60,9 @@ class Course < ApplicationRecord
# In the future when there is more info, this will be more complex to
# include class names/descriptions
filters = {}
q = query.gsub(" ", "")
q = query.delete(" ")
/[a-zA-Z]+/.match(q) { |a| filters["subject"] = a.to_s }
/\d+/.match(q) { |a| filters["course_number"] = a.to_s }
return filters
filters
end
end
......@@ -18,11 +18,11 @@ class CourseSection < ApplicationRecord
end
def self.from_crn(base_query, crn)
base_query.where("course_sections.crn = ?", value)
base_query.where("course_sections.crn = ?", crn)
end
def self.from_course_id(base_query, course_id)
base_query.where("course_sections.course_id = ?")
base_query.where("course_sections.course_id = ?", course_id)
end
# Select all revelevant course sections given the provided filters
......@@ -71,5 +71,4 @@ class CourseSection < ApplicationRecord
filters["title"] = query
filters
end
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