From ef34d1c5b5d6e3c0ccdaaf134dc09688512c93d0 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Sun, 1 Oct 2023 17:51:05 +0100 Subject: [PATCH] Update panopto scraping to separate lectures from recordings. Implement naive lecture creation on new recordings. --- app/jobs/scrape_panopto_job.rb | 13 ++++++++++++- app/models/lecture.rb | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/jobs/scrape_panopto_job.rb b/app/jobs/scrape_panopto_job.rb index cb9fc4b..a6d1270 100644 --- a/app/jobs/scrape_panopto_job.rb +++ b/app/jobs/scrape_panopto_job.rb @@ -23,7 +23,18 @@ class ScrapePanoptoJob < ApplicationJob } end - Recording.insert_all(attributes, unique_by: :recording_uuid) + created = Recording.insert_all(attributes, unique_by: :recording_uuid, returning: [:id, :title, :course_id, :start_time]) + + created.each do |new_recording_attrs| + new_recording = Recording.new(new_recording_attrs) + Lecture.create!( + title: new_recording.nice_title, + start_time: new_recording.start_time, + course_id: new_recording.course_id, + status: :undetermined, + recording_id: new_recording.id + ) + end end end end diff --git a/app/models/lecture.rb b/app/models/lecture.rb index ee5d000..5e2ebf8 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -1,7 +1,7 @@ class Lecture < ApplicationRecord belongs_to :course has_one :attendance - belongs_to :recording + belongs_to :recording, optional: true enum :status, [ :undetermined,