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

Started working on course_section fetch

parent 1033073a
Pipeline #2891 failed with stage
in 2 minutes and 20 seconds
......@@ -41,7 +41,7 @@ class Course < ApplicationRecord
# be used to run a query with fetch()
def self.parse_generic_query(query)
# In the future when there is more info, this will be more complex to
# include class names
# include class names/descriptions
filters = {}
q = query.gsub(" ", "")
/[a-zA-Z]+/.match(q) { |a| filters["subject"] = a.to_s }
......
......@@ -16,4 +16,26 @@ class CourseSection < ApplicationRecord
def self.with_instructor(name: "")
joins(:instructor).where("instructors.name LIKE ?", "%#{name}%").select('course_sections.*, instructors.name as instructor_name')
end
# Select all revelevant course sections given the provided filters
def self.fetch(filters)
query = CourseSection.select("*")
filter_list = CourseSection.parse_generic_query(filters["query"]) if filters.include? "query" else filters
filter_list.each do |filter, value|
if CourseSection.column_names.include? filter
case filter
when "crn"
query = query.where("crn = ?", value.upcase)
when "course_id"
query = query.where("course_id = ?", value)
end
end
end
end
def self.parse_generic_query(query)
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