From 7ffb8a0c3ffd9a6cbea72896701c0e9daac15d68 Mon Sep 17 00:00:00 2001 From: Juan Arias Date: Sat, 11 Nov 2023 15:48:30 -0300 Subject: [PATCH 1/2] feat(Seeds::Resources): Add rake task for seeding resources into the db * Three Users created for now.. will create Groups and Sessions later. --- api/db/seeds/resources.rb | 53 ++++++++++++++++++++++++++++++++++++ api/lib/tasks/resources.rake | 11 ++++++++ 2 files changed, 64 insertions(+) create mode 100644 api/db/seeds/resources.rb create mode 100644 api/lib/tasks/resources.rake diff --git a/api/db/seeds/resources.rb b/api/db/seeds/resources.rb new file mode 100644 index 00000000..a8393fdf --- /dev/null +++ b/api/db/seeds/resources.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +# Users +user_one = User.create!( + name: 'User One', + email: 'user.one@email.com', + password: 'Test#123', + confirmed_at: DateTime.now, + birth_date: DateTime.parse('2000-01-01'), + bio: 'This is User One\'s bio', + social_networks: { + facebook: 'foo', + instagram: 'bar' + }, + career_ids: [1], + subject_ids: [1, 2, 3] +) + +user_two = User.create!( + name: 'User Two', + email: 'user.two@email.com', + password: 'Test#123', + confirmed_at: DateTime.now, + birth_date: DateTime.parse('2000-01-01'), + bio: 'This is User Two\'s bio', + social_networks: { + facebook: 'foo', + instagram: 'bar' + }, + career_ids: [2], + subject_ids: [1, 2, 3] +) + +user_three = User.create!( + name: 'User Three', + email: 'user.three@email.com', + password: 'Test#123', + confirmed_at: DateTime.now, + birth_date: DateTime.parse('2000-01-01'), + bio: 'This is User Three\'s bio', + social_networks: { + facebook: 'foo', + instagram: 'bar' + }, + career_ids: [3], + subject_ids: [1, 2, 3] +) + +# Groups +# TODO: Create groups + +# Sessions +# TODO: Create sessions diff --git a/api/lib/tasks/resources.rake b/api/lib/tasks/resources.rake new file mode 100644 index 00000000..3d4e4149 --- /dev/null +++ b/api/lib/tasks/resources.rake @@ -0,0 +1,11 @@ +namespace :db do + namespace :seed do + Dir[Rails.root.join('db', 'seeds', '*.rb')].each do |filename| + task_name = File.basename(filename, '.rb') + desc "Seed #{task_name}, based on the file with the same name in `db/seeds/*.rb`" + task task_name.to_sym => :environment do + load(filename) if File.exist?(filename) + end + end + end +end From 89745d0a3c121e42da5d7c598aa34b9cc68158c3 Mon Sep 17 00:00:00 2001 From: Andres Date: Sun, 12 Nov 2023 17:34:08 -0300 Subject: [PATCH 2/2] seed task: group and session added --- README.md | 7 +++++ api/db/seeds/resources.rb | 64 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 40e00291..be1759dd 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,13 @@ $ cd finder/api $ bundle exec rails db:create db:migrate db:seed ``` +`Users`, `groups`, and test study `sessions` can also be created with the following commands: + +``` +$ cd finder/api +$ bundle exec rake db:seed:resources +``` + ### Start App Locally Run `api` (BE) and `client` (FE) separately. diff --git a/api/db/seeds/resources.rb b/api/db/seeds/resources.rb index a8393fdf..03292231 100644 --- a/api/db/seeds/resources.rb +++ b/api/db/seeds/resources.rb @@ -47,7 +47,67 @@ ) # Groups -# TODO: Create groups +group_one = Group.create!( + name: 'Group One', + description: 'This is Group One\'s description', + size: 10, + time_preferences: { + 'Friday' => 'None', + 'Sunday' => 'Morning' + }, + subject_id: 1 +) + +creator_member_one = group_one.members.create!( + user: user_one, + role: 'admin' +) + +group_one.members.create!( + user: user_three, + role: 'participant' +) + +group_two = Group.create!( + name: 'Group Two', + description: 'This is Group Two\'s description', + size: 8, + time_preferences: { + 'Monday' => 'Morning', + 'Wednesday' => 'Night' + }, + subject_id: 2 +) + +creator_member_two = group_two.members.create!( + user: user_two, + role: 'admin' +) + +group_two.members.create!( + user: user_three, + role: 'participant' +) # Sessions -# TODO: Create sessions +Session.create!( + name: 'Session One', + description: 'This is Session One\'s description', + location: 'Location One', + meeting_link: 'https://meet.example.com/session1', + start_time: DateTime.now + 1.day, + end_time: DateTime.now + 1.day + 2.hours, + group_id: group_one.id, + creator: creator_member_one +) + +Session.create!( + name: 'Session Two', + description: 'This is Session Two\'s description', + location: 'Location Two', + meeting_link: 'https://meet.example.com/session2', + start_time: DateTime.now + 2.days, + end_time: DateTime.now + 2.days + 2.5.hours, + group_id: group_two.id, + creator: creator_member_two +)