-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate home page and CSV parsing logic #32
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b63f193
Migrate homepage to schedule index
colbyendres bb476dd
Fixed RSpec failures
colbyendres c6e2c8e
Merge branch 'main' into move_home
colbyendres 51e4064
Migrate CSV logic to separate service
colbyendres 3c1a9a3
Update Cucumber scenarios
colbyendres dd10aa6
Change class name to satisfy autoloader
colbyendres 4aad6fa
Remove unused require
colbyendres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# frozen_string_literal: true | ||
|
||
class CsvHandler | ||
require 'csv' | ||
|
||
def upload(file) | ||
@file = file | ||
end | ||
|
||
def parse_room_csv(schedule_id) | ||
begin | ||
ActiveRecord::Base.transaction do | ||
room_data = CSV.parse(@file.read, headers: true) | ||
room_data.each do |row| | ||
Room.create!( | ||
schedule_id: schedule_id, | ||
campus: row['campus'], | ||
building_code: row['building_code'], | ||
room_number: row['room_number'], | ||
capacity: row['capacity'].to_i, | ||
is_lecture_hall: row['is_lecture_hall'] == 'True', | ||
is_learning_studio: row['is_learning_studio'] == 'True', | ||
is_lab: row['is_lab'] == 'True', | ||
is_active: row['is_active'] == 'True', | ||
comments: row['comments'] | ||
) | ||
end | ||
end | ||
# Flash data to be received by controller | ||
return { notice: 'Rooms successfully uploaded.' } | ||
rescue StandardError => e | ||
return { alert: "There was an error uploading the CSV file: #{e.message}" } | ||
end | ||
end | ||
|
||
def parse_instructor_csv(schedule_id) | ||
begin | ||
ActiveRecord::Base.transaction do | ||
instructor_data = CSV.parse(@file.read) | ||
actual_headers = instructor_data[1] | ||
required_headers = [ | ||
'anonimized ID', | ||
'First Name', | ||
'Last Name', | ||
'Email', | ||
'Teaching before 9:00 am.', | ||
'Teaching after 3:00 pm.', | ||
'Middle Name', | ||
'Is there anything else we should be aware of regarding your teaching load (special course reduction, ...)' # Optional: Include if needed | ||
] | ||
|
||
missing_headers = required_headers - actual_headers | ||
unless missing_headers.empty? | ||
return {alert: "Missing required headers: #{missing_headers.join(', ')}"} | ||
end | ||
|
||
instructor_data[2..].each do |row| | ||
# Extracting values and checking for nulls | ||
id_number = row[actual_headers.index('anonimized ID')] | ||
first_name = row[actual_headers.index('First Name')] | ||
last_name = row[actual_headers.index('Last Name')] | ||
middle_name = row[actual_headers.index('Middle Name')] | ||
email = row[actual_headers.index('Email')] | ||
before_9 = row[actual_headers.index('Teaching before 9:00 am.')] | ||
after_3 = row[actual_headers.index('Teaching after 3:00 pm.')] | ||
beaware_of = row[actual_headers.index('Is there anything else we should be aware of regarding your teaching load (special course reduction, ...)')] | ||
|
||
instructor_data = { | ||
schedule_id: schedule_id, | ||
id_number: id_number, | ||
first_name: first_name, | ||
last_name: last_name, | ||
middle_name: middle_name, | ||
email: email, | ||
before_9: before_9, | ||
after_3: after_3, | ||
beaware_of: beaware_of | ||
} | ||
|
||
Instructor.create(instructor_data) | ||
end | ||
end | ||
return {notice: 'Instructors successfully uploaded.'} | ||
rescue StandardError => e | ||
return {alert: "There was an error uploading the CSV file: #{e.message}"} | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR title