Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/controllers/participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def list_assignment_participants
if participants.nil?
render json: participants.errors, status: :unprocessable_entity
else
render json: participants, status: :ok
render json: participants.as_json(include: { user: { include: %i[role parent] } }), status: :ok
end
end

Expand Down Expand Up @@ -103,7 +103,7 @@ def update_authorization
# DELETE /participants/:id
def destroy
participant = Participant.find_by(id: params[:id])

if participant.nil?
render json: { error: 'Not Found' }, status: :not_found
elsif participant.destroy
Expand Down Expand Up @@ -139,8 +139,7 @@ def filter_user_participants(user)
# Filters participants based on the provided assignment
# Returns participants ordered by their IDs
def filter_assignment_participants(assignment)
participants = Participant.all
participants = participants.where(parent_id: assignment.id, type: 'AssignmentParticipant') if assignment
participants = Participant.where(parent_id: assignment.id, type: 'AssignmentParticipant') if assignment
participants.order(:id)
end

Expand Down
241 changes: 120 additions & 121 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,130 +1,129 @@
# frozen_string_literal: true

begin
#Create an instritution
inst_id = Institution.create!(
name: 'North Carolina State University',
# Create an instritution
inst_id = Institution.create!(
name: 'North Carolina State University'
).id

Role.create!(id: 1, name: 'Super Administrator')
Role.create!(id: 2, name: 'Administrator')
Role.create!(id: 3, name: 'Instructor')
Role.create!(id: 4, name: 'Teaching Assistant')
Role.create!(id: 5, name: 'Student')

# Create an admin user
User.create!(
name: 'admin',
email: '[email protected]',
password: 'password123',
full_name: 'admin admin',
institution_id: 1,
role_id: 1
)

# Generate Random Users
num_students = 48
num_assignments = 8
num_teams = 16
num_courses = 2
num_instructors = 2

puts "creating instructors"
instructor_user_ids = []
num_instructors.times do
instructor_user_ids << User.create(
name: Faker::Internet.unique.username,
email: Faker::Internet.unique.email,
password: "password",
full_name: Faker::Name.name,
institution_id: 1,
role_id: 3
).id
end

puts "creating courses"
course_ids = []
num_courses.times do |i|
course_ids << Course.create(
instructor_id: instructor_user_ids[i],
institution_id: inst_id,
directory_path: Faker::File.dir(segment_count: 2),
name: Faker::Company.industry,
info: "A fake class",
private: false
).id
end

puts "creating assignments"
assignment_ids = []
num_assignments.times do |i|
assignment_ids << Assignment.create(
name: Faker::Verb.base,
instructor_id: instructor_user_ids[i % num_instructors],
course_id: course_ids[i % num_courses],
has_teams: true,
private: false
).id
end

puts "creating teams"
team_ids = []
num_teams.times do |i|
team_ids << AssignmentTeam.create(
name: "Team #{i + 1}",
parent_id: assignment_ids[i % num_assignments]
).id

# Create an admin user
User.create!(
name: 'admin',
email: '[email protected]',
password: 'password123',
full_name: 'admin admin',
end

puts "creating students"
student_user_ids = []
num_students.times do
student_user_ids << User.create(
name: Faker::Internet.unique.username,
email: Faker::Internet.unique.email,
password: "password",
full_name: Faker::Name.name,
institution_id: 1,
role_id: 1
role_id: 5,
parent_id: [nil, *instructor_user_ids].sample
).id
end

puts "assigning students to teams"
teams_users_ids = []
# num_students.times do |i|
# teams_users_ids << TeamsUser.create(
# team_id: team_ids[i%num_teams],
# user_id: student_user_ids[i]
# ).id
# end

num_students.times do |i|
puts "Creating TeamsUser with team_id: #{team_ids[i % num_teams]}, user_id: #{student_user_ids[i]}"
teams_user = TeamsUser.create(
team_id: team_ids[i % num_teams],
user_id: student_user_ids[i]
)


#Generate Random Users
num_students = 48
num_assignments = 8
num_teams = 16
num_courses = 2
num_instructors = 2

puts "creating instructors"
instructor_user_ids = []
num_instructors.times do
instructor_user_ids << User.create(
name: Faker::Internet.unique.username,
email: Faker::Internet.unique.email,
password: "password",
full_name: Faker::Name.name,
institution_id: 1,
role_id: 3,
).id
end

puts "creating courses"
course_ids = []
num_courses.times do |i|
course_ids << Course.create(
instructor_id: instructor_user_ids[i],
institution_id: inst_id,
directory_path: Faker::File.dir(segment_count: 2),
name: Faker::Company.industry,
info: "A fake class",
private: false
).id
end

puts "creating assignments"
assignment_ids = []
num_assignments.times do |i|
assignment_ids << Assignment.create(
name: Faker::Verb.base,
instructor_id: instructor_user_ids[i%num_instructors],
course_id: course_ids[i%num_courses],
has_teams: true,
private: false
).id
end


puts "creating teams"
team_ids = []
num_teams.times do |i|
team_ids << AssignmentTeam.create(
name: "Team #{i + 1}",
parent_id: assignment_ids[i%num_assignments]
).id
end

puts "creating students"
student_user_ids = []
num_students.times do
student_user_ids << User.create(
name: Faker::Internet.unique.username,
email: Faker::Internet.unique.email,
password: "password",
full_name: Faker::Name.name,
institution_id: 1,
role_id: 5,
).id
if teams_user.persisted?
teams_users_ids << teams_user.id
puts "Created TeamsUser with ID: #{teams_user.id}"
else
puts "Failed to create TeamsUser: #{teams_user.errors.full_messages.join(', ')}"
end

puts "assigning students to teams"
teams_users_ids = []
#num_students.times do |i|
# teams_users_ids << TeamsUser.create(
# team_id: team_ids[i%num_teams],
# user_id: student_user_ids[i]
# ).id
#end

num_students.times do |i|
puts "Creating TeamsUser with team_id: #{team_ids[i % num_teams]}, user_id: #{student_user_ids[i]}"
teams_user = TeamsUser.create(
team_id: team_ids[i % num_teams],
user_id: student_user_ids[i]
)
if teams_user.persisted?
teams_users_ids << teams_user.id
puts "Created TeamsUser with ID: #{teams_user.id}"
else
puts "Failed to create TeamsUser: #{teams_user.errors.full_messages.join(', ')}"
end
end

puts "assigning participant to students, teams, courses, and assignments"
participant_ids = []
num_students.times do |i|
participant_ids << AssignmentParticipant.create(
user_id: student_user_ids[i],
parent_id: assignment_ids[i%num_assignments],
team_id: team_ids[i%num_teams],
).id
end








end

puts "assigning participant to students, teams, courses, and assignments"
participant_ids = []
num_students.times do |i|
puts "Creating AssignmentParticipant for user_id: #{student_user_ids[i]}, assignment_id: #{assignment_ids[i % num_assignments]}, team_id: #{team_ids[i % num_teams]}"
participant_ids << AssignmentParticipant.create(
user_id: student_user_ids[i],
parent_id: assignment_ids[i % num_assignments],
team_id: team_ids[i % num_teams],
handle: Faker::Internet.unique.username
).id
end
rescue ActiveRecord::RecordInvalid => e
puts 'The db has already been seeded'
puts e, 'The db has already been seeded'
end
Loading