From e8e143355d0a360047e67f4e15f7ad2da0be670e Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Sun, 4 Feb 2024 14:23:07 +0000 Subject: [PATCH] Add online property and live video URL to lecture models, as well as a default value at the course level --- app/models/course.rb | 11 +++++++++++ app/models/lecture.rb | 4 ---- ...0204140917_add_default_live_video_url_to_course.rb | 5 +++++ ...141120_add_online_and_live_video_url_to_lecture.rb | 6 ++++++ db/schema.rb | 5 ++++- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20240204140917_add_default_live_video_url_to_course.rb create mode 100644 db/migrate/20240204141120_add_online_and_live_video_url_to_lecture.rb diff --git a/app/models/course.rb b/app/models/course.rb index d40b0c6..0c140cf 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -41,6 +41,7 @@ class Course < ApplicationRecord short_lecture_title:, start_time:, event_uuid:, + online: summary.include?("LOIL"), } end @@ -65,6 +66,12 @@ class Course < ApplicationRecord title: title, start_time: event[:start_time], event_uuid: event[:event_uuid], + online: event[:online], + live_video_url: if event[:online] + self.default_live_video_url + else + nil + end, ) end end @@ -77,4 +84,8 @@ class Course < ApplicationRecord end end end + + def fill_in_default_live_video_url! + lectures.where(live_video_url: nil).update!(live_video_url: self.default_live_video_url) + end end diff --git a/app/models/lecture.rb b/app/models/lecture.rb index 07e2e4b..5dc4f9b 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -39,10 +39,6 @@ class Lecture < ApplicationRecord tracked_time_entries.review.sum(&:duration).seconds end - def live_video_url - nil - end - # NAIVE: Assumes that lectures are 50 minutes long, this is true currently but not assured. def end_time start_time + 50.hour diff --git a/db/migrate/20240204140917_add_default_live_video_url_to_course.rb b/db/migrate/20240204140917_add_default_live_video_url_to_course.rb new file mode 100644 index 0000000..0b24596 --- /dev/null +++ b/db/migrate/20240204140917_add_default_live_video_url_to_course.rb @@ -0,0 +1,5 @@ +class AddDefaultLiveVideoUrlToCourse < ActiveRecord::Migration[7.1] + def change + add_column :courses, :default_live_video_url, :string + end +end diff --git a/db/migrate/20240204141120_add_online_and_live_video_url_to_lecture.rb b/db/migrate/20240204141120_add_online_and_live_video_url_to_lecture.rb new file mode 100644 index 0000000..305b0cd --- /dev/null +++ b/db/migrate/20240204141120_add_online_and_live_video_url_to_lecture.rb @@ -0,0 +1,6 @@ +class AddOnlineAndLiveVideoUrlToLecture < ActiveRecord::Migration[7.1] + def change + add_column :lectures, :online, :boolean, default: false, null: false + add_column :lectures, :live_video_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 12ab8f9..19078e7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_04_133705) do +ActiveRecord::Schema[7.1].define(version: 2024_02_04_141120) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -24,6 +24,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_04_133705) do t.date "semester_start_date", default: "2023-10-02" t.string "homepage" t.boolean "archived", default: false, null: false + t.string "default_live_video_url" t.index ["toggl_project"], name: "index_courses_on_toggl_project", unique: true t.index ["unit_code"], name: "index_courses_on_unit_code", unique: true end @@ -37,6 +38,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_04_133705) do t.string "event_uuid" t.boolean "cancelled", default: false t.integer "kind", default: 0 + t.boolean "online", default: false, null: false + t.string "live_video_url" t.index ["course_id"], name: "index_lectures_on_course_id" end