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
Khalid Ali
schedules
Commits
8b0cf18d
Commit
8b0cf18d
authored
Jun 18, 2018
by
Zac Wood
Browse files
Renamed Section to CourseSection
parent
89b77445
Changes
15
Hide whitespace changes
Inline
Side-by-side
schedules_api/app/controllers/calendar_generator_controller.rb
View file @
8b0cf18d
...
...
@@ -6,7 +6,7 @@ class CalendarGeneratorController < ApplicationController
cal
=
Icalendar
::
Calendar
.
new
params
[
:_json
].
each
do
|
crn
|
# for each CRN sent by the post request
section
=
Section
.
find_by_crn
(
crn
)
section
=
Course
Section
.
find_by_crn
(
crn
)
event
=
generate_event_from_section
(
section
)
cal
.
add_event
(
event
)
end
...
...
@@ -17,7 +17,7 @@ class CalendarGeneratorController < ApplicationController
private
# Configures a calendar event from a given section
# @param section [Section]
# @param section [
Course
Section]
def
generate_event_from_section
(
section
)
event
=
Icalendar
::
Event
.
new
...
...
@@ -56,7 +56,7 @@ class CalendarGeneratorController < ApplicationController
# Generates a recurrence rule string descripting which day the class event
# should take place on
# @param section [Section]
# @param section [
Course
Section]
# @return [String]
def
recurrence_rule_str
(
section
)
days
=
section
.
days
.
split
(
""
).
map
do
|
day
|
...
...
@@ -67,7 +67,7 @@ class CalendarGeneratorController < ApplicationController
end
# Get all dates that should excluded from the schedule
# @param section [Section]
# @param section [
Course
Section]
# @return [Array]
def
exdates_for_section
(
section
)
# Generate exdates for all closures in a semester
...
...
schedules_api/app/controllers/sections_controller.rb
→
schedules_api/app/controllers/
course_
sections_controller.rb
View file @
8b0cf18d
# Contains all actions having to do with Sections.
# Contains all actions having to do with
Course
Sections.
# This is a nested controller -- see +config/routes.rb+ for details
class
SectionsController
<
ApplicationController
class
Course
SectionsController
<
ApplicationController
# Render JSON of all Sections belonging to a given Course.
def
index
@course
=
Course
.
find
(
params
[
:course_id
])
@sections
=
@course
.
sections
@sections
=
@course
.
course_
sections
render
json:
@sections
end
end
schedules_api/app/controllers/search_controller.rb
View file @
8b0cf18d
...
...
@@ -2,7 +2,7 @@ class SearchController < ApplicationController
def
index
if
params
.
key?
(
:crn
)
crn
=
params
[
:crn
]
@sections
=
Section
.
find_by_crn
(
crn
)
@sections
=
Course
Section
.
find_by_crn
(
crn
)
render
json:
@sections
else
render
status:
404
...
...
schedules_api/app/models/course.rb
View file @
8b0cf18d
...
...
@@ -10,9 +10,9 @@ class Course < ApplicationRecord
validates
:subject
,
presence:
true
validates
:semester_id
,
presence:
true
# Returns all +Section+ objects that belong to this course.
# Returns all +
Course
Section+ objects that belong to this course.
# @return [Array]
def
sections
Section
.
where
course_id:
id
def
course_
sections
Course
Section
.
where
course_id:
id
end
end
schedules_api/app/models/section.rb
→
schedules_api/app/models/
course_
section.rb
View file @
8b0cf18d
# Contains logic belonging to the +Section+ model.
# Contains logic belonging to the +
Course
Section+ model.
#
# TODO: Add more docs
class
Section
<
ApplicationRecord
# Each +Section+ belongs to a +Course+.
class
Course
Section
<
ApplicationRecord
# Each +
Course
Section+ belongs to a +Course+.
belongs_to
:course
# Ensure all necessary fields are present.
...
...
schedules_api/config/routes.rb
View file @
8b0cf18d
...
...
@@ -2,7 +2,7 @@
Rails
.
application
.
routes
.
draw
do
scope
:api
do
# Register /api routes
resources
:courses
,
only:
[
:index
]
do
# GET /api/courses
resources
:sections
,
only:
[
:index
]
# GET /api/courses/:course_id/sections
resources
:
course_
sections
,
only:
[
:index
]
# GET /api/courses/:course_id/sections
end
get
'search'
,
controller:
'search'
,
action:
'index'
...
...
schedules_api/db/excel_loader.rb
View file @
8b0cf18d
...
...
@@ -38,7 +38,7 @@ class ExcelLoader
def
delete_all_records
Semester
.
delete_all
Course
.
delete_all
Section
.
delete_all
Course
Section
.
delete_all
end
# Tries to create a course from a given row.
...
...
@@ -70,7 +70,7 @@ class ExcelLoader
# So, split the times string by the - character
times
=
row
.
cells
[
23
]
&
.
value
time_strs
=
times
.
split
(
'-'
)
section
=
Section
.
create
name:
section_name
,
section
=
Course
Section
.
create
name:
section_name
,
course:
@current_course
,
crn:
row
.
cells
[
6
]
&
.
value
,
section_type:
row
.
cells
[
8
]
&
.
value
,
...
...
schedules_api/db/migrate/20180619011649_change_section_to_course_section.rb
0 → 100644
View file @
8b0cf18d
class
ChangeSectionToCourseSection
<
ActiveRecord
::
Migration
[
5.1
]
def
change
rename_table
:sections
,
:course_sections
end
end
schedules_api/db/schema.rb
View file @
8b0cf18d
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20180
505195736
)
do
ActiveRecord
::
Schema
.
define
(
version:
20180
619011649
)
do
create_table
"closures"
,
force: :cascade
do
|
t
|
t
.
date
"date"
...
...
@@ -20,16 +20,7 @@ ActiveRecord::Schema.define(version: 20180505195736) do
t
.
index
[
"semester_id"
],
name:
"index_closures_on_semester_id"
end
create_table
"courses"
,
force: :cascade
do
|
t
|
t
.
string
"subject"
t
.
string
"course_number"
t
.
integer
"semester_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
index
[
"semester_id"
],
name:
"index_courses_on_semester_id"
end
create_table
"sections"
,
force: :cascade
do
|
t
|
create_table
"course_sections"
,
force: :cascade
do
|
t
|
t
.
string
"name"
t
.
string
"crn"
t
.
string
"section_type"
...
...
@@ -48,7 +39,16 @@ ActiveRecord::Schema.define(version: 20180505195736) do
t
.
integer
"course_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
index
[
"course_id"
],
name:
"index_sections_on_course_id"
t
.
index
[
"course_id"
],
name:
"index_course_sections_on_course_id"
end
create_table
"courses"
,
force: :cascade
do
|
t
|
t
.
string
"subject"
t
.
string
"course_number"
t
.
integer
"semester_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
index
[
"semester_id"
],
name:
"index_courses_on_semester_id"
end
create_table
"semesters"
,
force: :cascade
do
|
t
|
...
...
schedules_api/db/seeds.rb
View file @
8b0cf18d
...
...
@@ -33,7 +33,7 @@ ThreadsWait.all_waits(*threads)
# delete everything in the current database
Closure
.
delete_all
Section
.
delete_all
Course
Section
.
delete_all
Course
.
delete_all
Semester
.
delete_all
...
...
@@ -59,7 +59,7 @@ total.each do |subject, sections|
puts
"Adding
#{
section_name
}
..."
Section
.
create!
(
name:
section_name
,
Course
Section
.
create!
(
name:
section_name
,
crn:
section
[
:crn
],
section_type:
section
[
:type
],
title:
section
[
:title
],
...
...
schedules_api/test/controllers/course_sections_controller_test.rb
0 → 100644
View file @
8b0cf18d
require
'test_helper'
class
CourseSectionsControllerTest
<
ActionDispatch
::
IntegrationTest
test
'should get index'
do
# get url_for controller: 'course_sections', action: 'index', course_id: 1
get
url_for
controller:
'course_sections'
,
action:
'index'
,
course_id:
1
assert_response
:success
end
end
schedules_api/test/controllers/sections_controller_test.rb
deleted
100644 → 0
View file @
89b77445
require
'test_helper'
class
SectionsControllerTest
<
ActionDispatch
::
IntegrationTest
test
'should get index'
do
get
url_for
controller:
'sections'
,
action:
'index'
,
course_id:
1
assert_response
:success
end
end
schedules_api/test/fixtures/sections.yml
→
schedules_api/test/fixtures/
course_
sections.yml
View file @
8b0cf18d
File moved
schedules_api/test/models/section_test.rb
→
schedules_api/test/models/
course_
section_test.rb
View file @
8b0cf18d
require
'test_helper'
class
SectionTest
<
ActiveSupport
::
TestCase
class
Course
SectionTest
<
ActiveSupport
::
TestCase
test
'fails with improper data'
do
assert_raise
do
Section
.
create!
name:
nil
,
Course
Section
.
create!
name:
nil
,
crn:
nil
,
title:
nil
,
start_date:
nil
,
...
...
@@ -13,7 +13,7 @@ class SectionTest < ActiveSupport::TestCase
end
test
'succeeds with proper data'
do
Section
.
create!
name:
'Test section'
,
Course
Section
.
create!
name:
'Test section'
,
crn:
'12345'
,
title:
'Test title'
,
start_date:
Time
.
zone
.
today
,
...
...
schedules_api/test/models/excel_loader_test.rb
View file @
8b0cf18d
...
...
@@ -9,6 +9,6 @@ class ExcelLoaderTest < ActiveSupport::TestCase
assert
(
Semester
.
count
>
NUMBER_ADDED_BY_FIXTURES
,
'No semester loaded'
)
assert
(
Course
.
count
>
NUMBER_ADDED_BY_FIXTURES
,
'No courses loaded'
)
assert
(
Section
.
count
>
NUMBER_ADDED_BY_FIXTURES
,
'No sections loaded'
)
assert
(
Course
Section
.
count
>
NUMBER_ADDED_BY_FIXTURES
,
'No sections loaded'
)
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