diff --git a/app/models/assignment.rb b/app/models/assignment.rb new file mode 100644 index 0000000..acb9437 --- /dev/null +++ b/app/models/assignment.rb @@ -0,0 +1,7 @@ +class Assignment < ApplicationRecord + #Relationship with Lms + belongs_to :lms + + #Relationship with Extension + has_many :extensions +end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index d1af702..41de79c 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,4 +1,5 @@ class Course < ApplicationRecord + # Associations has_many :course_to_lmss has_many :lmss, through: :course_to_lmss @@ -7,4 +8,5 @@ class Course < ApplicationRecord # Validations validates :course_name, presence: true + end \ No newline at end of file diff --git a/app/models/course_to_lms.rb b/app/models/course_to_lms.rb index 04faa5a..8496251 100644 --- a/app/models/course_to_lms.rb +++ b/app/models/course_to_lms.rb @@ -1,4 +1,5 @@ class CourseToLms < ApplicationRecord + # Associations belongs_to :course belongs_to :lms @@ -6,4 +7,5 @@ class CourseToLms < ApplicationRecord # Validations validates :course_id, presence: true validates :lms_id, presence: true + end \ No newline at end of file diff --git a/app/models/extension.rb b/app/models/extension.rb new file mode 100644 index 0000000..ea5f41b --- /dev/null +++ b/app/models/extension.rb @@ -0,0 +1,7 @@ +class Extension < ApplicationRecord + #Relationship with Assignment + belongs_to :assignment + + #Relationship with User + has_one :user +end \ No newline at end of file diff --git a/app/models/lms.rb b/app/models/lms.rb new file mode 100644 index 0000000..743cdcb --- /dev/null +++ b/app/models/lms.rb @@ -0,0 +1,8 @@ +class Lms < ApplicationRecord + #Relationship with Course (and CourseToLms) + has_many :course_to_lmss + has_many :courses, :through => :course_to_lmss + + #Relationship with Assignment + has_many :assignments +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index a17da6f..c88fc18 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,8 +3,13 @@ class User < ApplicationRecord validates :email, presence: true, uniqueness: true validates :email, format: { with: URI::MailTo::EMAIL_REGEXP, message: 'must be a valid email address' } - # Associasions + # Associations has_many :lms_credentials, dependent: :destroy - has_many :user_to_courses + + # Relationship with Extension has_many :extensions + + #Relationship with Course (and UserToCourse) + has_many :user_to_courses + has_many :courses, :through => :user_to_courses end \ No newline at end of file diff --git a/app/models/user_to_course.rb b/app/models/user_to_course.rb new file mode 100644 index 0000000..e7fee1c --- /dev/null +++ b/app/models/user_to_course.rb @@ -0,0 +1,4 @@ +class UserToCourse < ApplicationRecord + belongs_to :user + belongs_to :course +end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 4fbd6ed..dc36945 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,3 +7,86 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end + +LmsCredential.destroy_all +Extension.destroy_all +Assignment.destroy_all +CourseToLms.destroy_all +UserToCourse.destroy_all +Course.destroy_all +Lms.destroy_all +User.destroy_all + +canvas = Lms.create!({ + lms_name: "Canvas", + use_auth_token: true +}) + + +test_assignment = Assignment.create!({ + lms_id: canvas.id, + name: "Test Assignment", + external_assignment_id: "11111" +}) + + +test_course = Course.create!({ + course_name: "Test Course", +}) + +test_course_to_lms = CourseToLms.create!({ + lms_id: canvas.id, + course_id: test_course.id, + external_course_id: "22222" +}) + +test_user = User.create!({ + email: "testuser@example.com", +}) + +test_user_to_course = UserToCourse.create!({ + user_id: test_user.id, + course_id: test_course.id, + role: "test" +}) + +test_extension = Extension.create!({ + assignment_id: test_assignment.id, + student_email: "teststudent@example.com", + initial_due_date: DateTime.iso8601('2024-04-20'), + new_due_date: DateTime.iso8601('2024-04-30'), + last_processed_by_id: test_user.id, + external_extension_id: "33333" +}) + +test_lms_credential = LmsCredential.create!({ + user_id: test_user.id, + lms_name: "canvas", + token: "test token", + external_user_id: "44444" +}) + +real_course = Course.create!({ + course_name: "CS169L Flextension", +}) + +real_course_to_lms = CourseToLms.create!({ + lms_id: canvas.id, + course_id: real_course.id, + external_course_id: "1534405" +}) + +real_assignment = Assignment.create!({ + lms_id: canvas.id, + name: "Seed Data Testing", + external_assignment_id: "8741483" +}) + +real_extension = Extension.create!({ + assignment_id: real_assignment.id, + student_email: "teststudent@example.com", + initial_due_date: DateTime.iso8601('2024-04-20'), + new_due_date: DateTime.iso8601('2024-04-27'), + last_processed_by_id: test_user.id, + external_extension_id: "270163" +}) \ No newline at end of file