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
7a2a9aff
Commit
7a2a9aff
authored
Feb 10, 2019
by
Zac Wood
Browse files
rubo
👮
parent
43791089
Pipeline
#3850
passed with stage
in 2 minutes and 45 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
schedules/app/controllers/api/course_sections_controller.rb
View file @
7a2a9aff
...
...
@@ -11,10 +11,10 @@ class API::CourseSectionsController < ApplicationController
param
:instructor
,
String
,
desc:
"Get course sections being taught by this instructor"
def
index
@sections
=
CourseSection
.
where
(
semester:
@semester
)
.
joins
(
:course
)
.
joins
(
:instructor
)
.
select
(
'course_sections.*, instructors.name AS instructor_name'
)
.
where
(
semester:
@semester
)
.
joins
(
:course
)
.
joins
(
:instructor
)
.
select
(
'course_sections.*, instructors.name AS instructor_name'
)
if
params
.
key?
(
:course_id
)
@sections
=
@sections
.
where
(
course_id:
params
[
:course_id
])
...
...
schedules/app/controllers/api/semesters_controller.rb
View file @
7a2a9aff
...
...
@@ -7,7 +7,7 @@ class API::SemestersController < ApplicationController
year:
s
.
year
}
end
render
json:
result
end
end
schedules/app/models/course_section.rb
View file @
7a2a9aff
...
...
@@ -3,8 +3,8 @@ class CourseSection < ApplicationRecord
# Each +CourseSection+ belongs to a +Course+ and an +Instructor+.
belongs_to
:course
belongs_to
:instructor
# Each course belongs to a +Semester+
# Each course belongs to a +Semester+
belongs_to
:semester
# Ensure all necessary fields are present.
...
...
schedules/db/seeds.rb
View file @
7a2a9aff
...
...
@@ -119,7 +119,6 @@ def main
parser
.
parse_semesters
[
0
..
6
]
end
puts
"
\t
Parsing subjects..."
subjects
=
parser
.
parse_subjects
(
semesters
.
first
[
:value
])
...
...
@@ -128,7 +127,7 @@ def main
puts
"
\t
Loading courses..."
load_courses
(
courses
)
semesters
.
each
do
|
semester
|
puts
"
#{
semester
[
:season
]
}
#{
semester
[
:year
]
}
"
db_semester
=
Semester
.
find_or_create_by!
(
season:
semester
[
:season
],
year:
semester
[
:year
])
...
...
schedules/test/controllers/api/course_sections_controller_test.rb
View file @
7a2a9aff
...
...
@@ -4,13 +4,13 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
test
'should get index'
do
get
api_course_sections_url
(
course_id:
courses
(
:cs112
).
id
,
semester_id:
semesters
(
:fall2018
).
id
)
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
num_sections
=
CourseSection
.
where
(
course_id:
courses
(
:cs112
).
id
)
.
where
(
semester:
semesters
(
:fall2018
)).
count
.
where
(
course_id:
courses
(
:cs112
).
id
)
.
where
(
semester:
semesters
(
:fall2018
)).
count
assert_equal
num_sections
,
sections_returned
.
count
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