Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules
Commits
e68cc60f
Commit
e68cc60f
authored
Sep 14, 2018
by
Zach Perkins
Browse files
Started working on course_section fetch
parent
1033073a
Pipeline
#2891
failed with stage
in 2 minutes and 20 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
schedules_api/app/models/course.rb
View file @
e68cc60f
...
...
@@ -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
}
...
...
schedules_api/app/models/course_section.rb
View file @
e68cc60f
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment