diff --git a/schedules_api/Dockerfile b/schedules_api/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b9f1db13f39dc09dff0bbae9b230c321a571a4b4 --- /dev/null +++ b/schedules_api/Dockerfile @@ -0,0 +1,8 @@ +FROM ruby:2.5 + +RUN mkdir /api +WORKDIR /api +ADD . /api + +RUN bundle install --without development +ENV RAILS_ENV=production diff --git a/schedules_api/Gemfile b/schedules_api/Gemfile index c15bbb806c5b83dcf365f502d797ab1833b578f9..18839954dfcf5816929907decab2c878fdfd3980 100644 --- a/schedules_api/Gemfile +++ b/schedules_api/Gemfile @@ -12,11 +12,6 @@ gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.7' # Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' -# Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' -# See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' diff --git a/schedules_api/app/controllers/calendar_generator_controller.rb b/schedules_api/app/controllers/calendar_generator_controller.rb index a55f4420d40d94b967485c845c26a47ae8c25b7b..a81e9640c3344b88775ea4977379bf30f7b4eba1 100644 --- a/schedules_api/app/controllers/calendar_generator_controller.rb +++ b/schedules_api/app/controllers/calendar_generator_controller.rb @@ -1,10 +1,14 @@ require 'icalendar' require 'time' +# Contains functionality for generating schedules. class CalendarGeneratorController < ApplicationController - def generate + # Render an iCal file containing the schedules of all the + # course sections with the given CRNs. + def new cal = Icalendar::Calendar.new - + + # the intended format for the json is a list of CRNs params[:_json].each do |crn| # for each CRN sent by the post request section = CourseSection.find_by_crn(crn) event = generate_event_from_section(section) diff --git a/schedules_api/app/controllers/course_sections_controller.rb b/schedules_api/app/controllers/course_sections_controller.rb index 29b46c7e33f8b2f6e71761064968f52fee0534d0..031712d0452628c730f7f516c4913338e5fc861f 100644 --- a/schedules_api/app/controllers/course_sections_controller.rb +++ b/schedules_api/app/controllers/course_sections_controller.rb @@ -4,7 +4,6 @@ class CourseSectionsController < ApplicationController # Render JSON of all Sections belonging to a given Course. def index @sections = CourseSection.where(course_id: params[:course_id]) - render json: @sections end end diff --git a/schedules_api/app/controllers/courses_controller.rb b/schedules_api/app/controllers/courses_controller.rb index 6fea50765967975c913678faee6beebc28ca0c2a..03ca664735a8a7988c5e7d6ba52135d384ff4c23 100644 --- a/schedules_api/app/controllers/courses_controller.rb +++ b/schedules_api/app/controllers/courses_controller.rb @@ -4,9 +4,10 @@ class CoursesController < ApplicationController def index @courses = Course.all + # filter by subject + course number if the params are included @courses = @courses.where(subject: params[:subject].upcase) if params.key?(:subject) @courses = @courses.where(course_number: params[:course_number]) if params.key?(:course_number) - + render json: @courses end diff --git a/schedules_api/app/controllers/search_controller.rb b/schedules_api/app/controllers/search_controller.rb deleted file mode 100644 index c3dd62eda68b7476531de4c12fbdb054b3f2410e..0000000000000000000000000000000000000000 --- a/schedules_api/app/controllers/search_controller.rb +++ /dev/null @@ -1,11 +0,0 @@ -class SearchController < ApplicationController - def index - if params.key?(:crn) - crn = params[:crn] - @sections = CourseSection.find_by_crn(crn) - render json: @sections - else - render status: 404 - end - end -end diff --git a/schedules_api/config/environments/production.rb b/schedules_api/config/environments/production.rb index cd158056952f5414b2116357b944756d3fe9a92e..31f724e261c2f3669b7711628184ec37ec29f72e 100644 --- a/schedules_api/config/environments/production.rb +++ b/schedules_api/config/environments/production.rb @@ -17,7 +17,7 @@ Rails.application.configure do # Attempt to read encrypted secrets from `config/secrets.yml.enc`. # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or # `config/secrets.yml.key`. - config.read_encrypted_secrets = true + # config.read_encrypted_secrets = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. diff --git a/schedules_api/config/routes.rb b/schedules_api/config/routes.rb index 32d3c27e3ed35f72562ca6a4f267bbaece259efc..5d7f3d3d93908fb782317a21252e83945052e12a 100644 --- a/schedules_api/config/routes.rb +++ b/schedules_api/config/routes.rb @@ -4,7 +4,7 @@ Rails.application.routes.draw do resources :courses, only: [:index, :show] resources :course_sections, only: [:index] - post 'generate', controller: 'calendar_generator', action: 'generate' + post 'generate', controller: 'calendar_generator', action: 'new' end root 'courses#index' # Set the root to be the courses API endpoint diff --git a/schedules_api/db/data/allsections.xlsx b/schedules_api/db/data/allsections.xlsx deleted file mode 100644 index 2ea3d4b8570f5aa6b761f842c99fa33f105325d5..0000000000000000000000000000000000000000 Binary files a/schedules_api/db/data/allsections.xlsx and /dev/null differ diff --git a/schedules_api/db/seeds.rb b/schedules_api/db/seeds.rb index e10d18bfa88a92ec4b83487d88a08cd14b41bcd0..dcb3d74df5178a3f7b35c4ee1f4edf69eec3a1a4 100644 --- a/schedules_api/db/seeds.rb +++ b/schedules_api/db/seeds.rb @@ -14,8 +14,8 @@ parser = PatriotWeb::Parser.new # get the first semester only semester = parser.parse_semesters.first -puts "DDOSing Patriot Web, buckle up kids -" +puts "DDOSing Patriot Web, buckle up kids" + # parse all subjects and their courses in the semester parser.parse_subjects(semester).each do |subject| puts "Getting courses for #{subject}" diff --git a/schedules_api/start.sh b/schedules_api/start.sh new file mode 100755 index 0000000000000000000000000000000000000000..856271c45afb89c5293aaa39e41003bb92981de1 --- /dev/null +++ b/schedules_api/start.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +export SECRET_KEY_BASE=$(rails secret) +cp db/development.sqlite3 db/production.sqlite3 +rails s diff --git a/schedules_api/test/controllers/calendar_generator_controller_test.rb b/schedules_api/test/controllers/calendar_generator_controller_test.rb index 5d43ad3487e60ad522d8c66d92df103c9d2dd601..a24dc1beb323162321abac3d6a4128ce8ebb3a71 100644 --- a/schedules_api/test/controllers/calendar_generator_controller_test.rb +++ b/schedules_api/test/controllers/calendar_generator_controller_test.rb @@ -2,7 +2,16 @@ require 'test_helper' class CalendarGeneratorControllerTest < ActionDispatch::IntegrationTest test "should get generate" do - assert true # TODO: Implement test - # assert_response :success + crns = [course_sections(:cs112001).crn, course_sections(:cs112002).crn] + post "/api/generate", params: crns.to_json, headers: { 'CONTENT_TYPE' => 'application/json' } + + # DTSTAMP and UID lines uniquely identify events, so we can't test against them. + # so remove all the lines starting with them. + # the \r characters are also annoying so just remove them too + gen = @response.body.split("\n").select {|line| !line.include?("DTSTAMP") && !line.include?("UID")}.join("\n").gsub(/\r/, "") + correct_ical = File.open("test/test.ics").read.gsub(/\r/, "") + assert_equal correct_ical, gen end end + + diff --git a/schedules_api/test/controllers/courses_controller_test.rb b/schedules_api/test/controllers/courses_controller_test.rb index 013824835bcb83dda2ffe30af95274690a049693..c0d1b4e5316f7b70c731abdaaecfbb8292c87851 100644 --- a/schedules_api/test/controllers/courses_controller_test.rb +++ b/schedules_api/test/controllers/courses_controller_test.rb @@ -10,8 +10,8 @@ class CoursesControllerTest < ActionDispatch::IntegrationTest assert_equal courses_count, courses_returned.count end - test '#index should return filtered by subject' do - get courses_url subject: "CS" + test '#index should return filtered by subject case insensitive' do + get courses_url subject: "Cs" assert_response :success courses_returned = JSON.parse @response.body diff --git a/schedules_api/test/fixtures/closures.yml b/schedules_api/test/fixtures/closures.yml index 3c6319eb525832ca4bf0e41fa6269d21945b811c..fa5444ab56e61dd0c818a7433ccb89619b4c0570 100644 --- a/schedules_api/test/fixtures/closures.yml +++ b/schedules_api/test/fixtures/closures.yml @@ -1,9 +1,9 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html may1st: # tuesday - date: 2018-05-01 - semester: one + date: <%= Date.new(2018, 5, 30) %> + semester: fall2018 may2nd: # wednesday - date: 2018-05-02 - semester: two + date: <%= Date.new(2018, 5, 31) %> + semester: fall2018 diff --git a/schedules_api/test/fixtures/course_sections.yml b/schedules_api/test/fixtures/course_sections.yml index 2aa1698c40f3306788d90309d9c9af3f358d27db..54f76ed1a9ae90d226727e6704aa2113d2df9d57 100644 --- a/schedules_api/test/fixtures/course_sections.yml +++ b/schedules_api/test/fixtures/course_sections.yml @@ -6,11 +6,11 @@ cs112001: section_type: MyString title: MyString instructor: MyString - start_date: 2018-04-07 - end_date: 2018-04-07 - days: MyString - start_time: MyString - end_time: MyString + start_date: 2018-05-21 + end_date: 2018-06-04 + days: MWF + start_time: 12:00 pm + end_time: 1:00 pm location: MyString status: MyString campus: MyString @@ -24,11 +24,11 @@ cs112002: section_type: MyString title: MyString instructor: MyString - start_date: 2018-04-07 - end_date: 2018-04-07 - days: MyString - start_time: MyString - end_time: MyString + start_date: 2018-05-21 + end_date: 2018-06-04 + days: TR + start_time: 11:00 am + end_time: 2:00 pm location: MyString status: MyString campus: MyString @@ -42,11 +42,11 @@ cs211001: section_type: MyString title: MyString instructor: MyString - start_date: 2018-04-07 - end_date: 2018-04-07 - days: MyString - start_time: MyString - end_time: MyString + start_date: 2018-05-21 + end_date: 2018-06-04 + days: TR + start_time: 2:30 pm + end_time: 3:00 pm location: MyString status: MyString campus: MyString diff --git a/schedules_api/test/test.ics b/schedules_api/test/test.ics new file mode 100644 index 0000000000000000000000000000000000000000..94ea2c4d3a4f9567ca73a8b45a20fd59e71a474c --- /dev/null +++ b/schedules_api/test/test.ics @@ -0,0 +1,26 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:icalendar-ruby +CALSCALE:GREGORIAN +BEGIN:VEVENT +DTSTART:20180521T120000 +DTEND:20180521T130000 +DESCRIPTION:MyString +LOCATION:MyString +SUMMARY:MyString +RRULE:FREQ=WEEKLY;UNTIL=20180604T130000;BYDAY=MO,WE,FR +EXDATE:20180530T120000 +EXDATE:20180531T120000 +END:VEVENT +BEGIN:VEVENT +DTSTART:20180521T110000 +DTEND:20180521T140000 +DESCRIPTION:MyString +LOCATION:MyString +SUMMARY:MyString2 +RRULE:FREQ=WEEKLY;UNTIL=20180604T140000;BYDAY=TU,TH +EXDATE:20180530T110000 +EXDATE:20180531T110000 +EXDATE:20180521T110000 +END:VEVENT +END:VCALENDAR \ No newline at end of file