From 9db9c10131ad2695af1cea42261645b8fc701e26 Mon Sep 17 00:00:00 2001 From: Martina Viola Date: Tue, 22 Apr 2025 09:34:03 -0400 Subject: [PATCH] updates questionnaire data retrieval for CSC 517 - E2538 --- .DS_Store | Bin 0 -> 6148 bytes .github/.DS_Store | Bin 0 -> 6148 bytes Gemfile | 2 +- Gemfile.lock | 208 ++++++++---------- .../api/v1/assignments_controller.rb | 62 +++++- .../api/v1/participants_controller.rb | 169 +++++++++++++- .../api/v1/questionnaires_controller.rb | 30 ++- app/models/Item.rb | 2 +- app/models/questionnaire.rb | 22 +- config/.DS_Store | Bin 0 -> 6148 bytes config/database.yml | 47 +++- config/database.yml.example | 55 ----- config/routes.rb | 13 +- .../20250314201309_add_name_to_teams.rb | 5 + ...ename_question_id_to_item_id_in_answers.rb | 5 + db/schema.rb | 7 +- db/seeds.rb | 33 ++- 17 files changed, 457 insertions(+), 203 deletions(-) create mode 100644 .DS_Store create mode 100644 .github/.DS_Store create mode 100644 config/.DS_Store delete mode 100644 config/database.yml.example create mode 100644 db/migrate/20250314201309_add_name_to_teams.rb create mode 100644 db/migrate/20250323223202_rename_question_id_to_item_id_in_answers.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..42690c807ae69cdff3a0e3bc1375f6a899cf6500 GIT binary patch literal 6148 zcmeHKOHRWu5Pj2>QpBc9mOcRzH;Afo0xm$4K&cd(O3;0d&Ku99YD5;S5JEGO{p|VK zep2iV09l`!2VezY$)+eem=IM@nr7~NLzJB34JTC1N8MK4M54c_(!F2f9y{#uiHrSr zt#0>MR^2EPZ*5|GW>ZnWUI!G8 lM?V3a=sj|mjb=|ereEpU8)_ES=Wt^D2xLN{3kH6HfiJw)J6iw% literal 0 HcmV?d00001 diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..127299e8a826f391959f5c9d0ab1f804f003e56d GIT binary patch literal 6148 zcmeHK%Sr=55Ukc5B3^RzIKPlT7((&|{(xxk;=+PKyza^G%BQ9JffzPk0$!vVx@)Gl zYlo@B_BH_9eC*f23c!-?h%XOw^XKj}yQz#3>3qj428{T`VSkuaUrsppj*JoSc>BqJ z8J@>+xJ*)33P=GdAO)m=6u4Re@4d9;eWIcikOETRTLJ$*G`eFioD$>H!4M+=alv#L z*D*^Fn 0.5.5' -gem 'puma', '~> 5.0' +gem 'puma', '>= 6.0' gem 'rails', '~> 8.0', '>= 8.0.1' gem 'rswag-api' gem 'rswag-ui' diff --git a/Gemfile.lock b/Gemfile.lock index bd42d1751..c4ca32d6f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -72,63 +72,62 @@ GEM securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) base64 (0.2.0) - bcrypt (3.1.19) + bcrypt (3.1.20) benchmark (0.4.0) bigdecimal (3.1.9) bootsnap (1.18.4) msgpack (~> 1.2) - builder (3.2.4) + builder (3.3.0) concurrent-ruby (1.3.5) connection_pool (2.5.0) - coveralls (0.7.1) - multi_json (~> 1.3) - rest-client - simplecov (>= 0.7) - term-ansicolor - thor + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) crass (1.0.6) date (3.4.1) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) - diff-lcs (1.5.0) - docile (1.4.0) - domain_name (0.6.20240107) + debug (1.10.0) + irb (~> 1.10) + reline (>= 0.3.8) + diff-lcs (1.6.0) + docile (1.4.1) drb (2.2.1) - erubi (1.12.0) - factory_bot (6.2.1) - activesupport (>= 5.0.0) - factory_bot_rails (6.2.0) - factory_bot (~> 6.2.0) + erubi (1.13.1) + factory_bot (6.5.1) + activesupport (>= 6.1.0) + factory_bot_rails (6.4.4) + factory_bot (~> 6.5) railties (>= 5.0.0) - faker (3.2.0) + faker (3.5.1) i18n (>= 1.8.11, < 2) find_with_order (1.3.1) activerecord (>= 3) globalid (1.2.1) activesupport (>= 6.1) - http-accept (1.7.0) - http-cookie (1.0.8) - domain_name (~> 0.5) - i18n (1.14.1) + i18n (1.14.7) concurrent-ruby (~> 1.0) - io-console (0.6.0) + io-console (0.8.0) irb (1.15.1) pp (>= 0.6.0) rdoc (>= 4.0.0) reline (>= 0.4.2) - json (2.6.3) - json-schema (3.0.0) - addressable (>= 2.8) - jwt (2.7.1) - language_server-protocol (3.17.0.3) + json (2.10.1) + json-schema (5.1.1) + addressable (~> 2.8) + bigdecimal (~> 3.1) + jwt (2.10.1) + base64 + language_server-protocol (3.17.0.4) lingua (0.6.2) + lint_roller (1.1.0) logger (1.6.6) - loofah (2.21.3) + loofah (2.24.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -137,15 +136,10 @@ GEM net-pop net-smtp marcel (1.0.4) - mime-types (3.6.0) - logger - mime-types-data (~> 3.2015) - mime-types-data (3.2025.0204) mini_mime (1.1.5) - minitest (5.19.0) + minitest (5.25.4) msgpack (1.8.0) - multi_json (1.15.0) - mysql2 (0.5.5) + mysql2 (0.5.6) net-imap (0.5.6) date net-protocol @@ -155,18 +149,11 @@ GEM timeout net-smtp (0.5.1) net-protocol - netrc (0.11.0) - nio4r (2.5.9) - nokogiri (1.15.2-aarch64-linux) - racc (~> 1.4) - nokogiri (1.15.2-arm64-darwin) + nio4r (2.7.4) + nokogiri (1.18.3-arm64-darwin) racc (~> 1.4) - nokogiri (1.15.2-x64-mingw-ucrt) - racc (~> 1.4) - nokogiri (1.15.2-x86_64-linux) - racc (~> 1.4) - parallel (1.23.0) - parser (3.2.2.3) + parallel (1.26.3) + parser (3.3.7.1) ast (~> 2.4.1) racc pp (0.6.2) @@ -175,20 +162,20 @@ GEM psych (5.2.3) date stringio - public_suffix (5.0.3) - puma (5.6.6) + public_suffix (6.0.1) + puma (6.6.0) nio4r (~> 2.0) - racc (1.7.1) - rack (2.2.8) - rack-cors (2.0.1) + racc (1.8.1) + rack (3.1.11) + rack-cors (2.0.2) rack (>= 2.0.0) - rack-session (1.0.2) - rack (< 3) - rack-test (2.1.0) + rack-session (2.1.0) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) rack (>= 1.3) - rackup (1.0.1) - rack (< 3) - webrick + rackup (2.2.1) + rack (>= 3) rails (8.0.1) actioncable (= 8.0.1) actionmailbox (= 8.0.1) @@ -207,9 +194,9 @@ GEM activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) + rails-html-sanitizer (1.6.2) loofah (~> 2.21) - nokogiri (~> 1.14) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) railties (8.0.1) actionpack (= 8.0.1) activesupport (= 8.0.1) @@ -219,35 +206,29 @@ GEM thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.0.6) + rake (13.2.1) rdoc (6.12.0) psych (>= 4.0.0) - regexp_parser (2.8.1) + regexp_parser (2.10.0) reline (0.6.0) io-console (~> 0.5) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) - rexml (3.2.6) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec-core (3.13.3) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (6.0.3) - actionpack (>= 6.1) - activesupport (>= 6.1) - railties (>= 6.1) - rspec-core (~> 3.12) - rspec-expectations (~> 3.12) - rspec-mocks (~> 3.12) - rspec-support (~> 3.12) - rspec-support (3.12.1) + rspec-support (~> 3.13.0) + rspec-rails (7.1.1) + actionpack (>= 7.0) + activesupport (>= 7.0) + railties (>= 7.0) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.2) rswag-api (2.16.0) activesupport (>= 5.2, < 8.1) railties (>= 5.2, < 8.1) @@ -259,57 +240,52 @@ GEM rswag-ui (2.16.0) actionpack (>= 5.2, < 8.1) railties (>= 5.2, < 8.1) - rubocop (1.55.1) + rubocop (1.73.2) json (~> 2.3) - language_server-protocol (>= 3.17.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) - parser (>= 3.2.2.3) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.38.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.38.1) + parser (>= 3.3.1.0) ruby-progressbar (1.13.0) securerandom (0.4.1) - simplecov (0.22.0) + simplecov (0.16.1) docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) simplecov_json_formatter (0.1.4) - spring (4.1.1) - stringio (3.1.4) + spring (4.2.1) + stringio (3.1.5) sync (0.5.0) term-ansicolor (1.11.2) tins (~> 1.0) - thor (1.2.2) + thor (1.3.2) timeout (0.4.3) tins (1.38.0) bigdecimal sync tzinfo (2.0.6) concurrent-ruby (~> 1.0) - tzinfo-data (1.2023.3) - tzinfo (>= 1.0.0) - unicode-display_width (2.4.2) - uri (1.0.2) + unicode-display_width (3.1.4) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + uri (1.0.3) useragent (0.16.11) - webrick (1.9.1) websocket-driver (0.7.7) base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.11) + zeitwerk (2.7.2) PLATFORMS - aarch64-linux - arm64-darwin-22 - arm64-darwin-23 - x64-mingw-ucrt - x86_64-linux + arm64-darwin DEPENDENCIES bcrypt (~> 3.1.7) @@ -322,7 +298,7 @@ DEPENDENCIES jwt (~> 2.7, >= 2.7.1) lingua mysql2 (~> 0.5.5) - puma (~> 5.0) + puma (>= 6.0) rack-cors rails (~> 8.0, >= 8.0.1) rspec-rails @@ -339,4 +315,4 @@ RUBY VERSION ruby 3.2.7p253 BUNDLED WITH - 2.4.14 + 2.6.6 diff --git a/app/controllers/api/v1/assignments_controller.rb b/app/controllers/api/v1/assignments_controller.rb index fdaf9bc75..a0b671050 100644 --- a/app/controllers/api/v1/assignments_controller.rb +++ b/app/controllers/api/v1/assignments_controller.rb @@ -209,7 +209,67 @@ def varying_rubrics_by_round? end end end - + + + def list_submissions + assignment = Assignment.includes(:teams, :participants).find(params[:id]) + + submissions = if assignment.team_assignment? + assignment.teams.includes(:users).map do |team| + signed_up_team = team.signed_up_teams.first + topic = signed_up_team&.sign_up_topic&.topic_name + { + id: team.participants.first.id, + name: team.name, + participants: team.users, + team_id: team.id, + topic: topic, + } + end + else + assignment.participants.includes(:user).map do |participant| + { + id: participant.id, + name: participant.user.name, + participants: [participant.user] + } + end + end + + render json: submissions, status: :ok + end + + + def get_team + team = Team.includes(:users).find_by(id: params[:team_id]) + + if team.nil? + render json: { error: "Team not found" }, status: :not_found + else + # render json: team.to_json(include: :participants), status: :ok + # render json: team.to_json( + # include: { + # participants: { + # include: { + # user: { only: [:name, :full_name] } + # } + # } + # } + # ), status: :ok + render json: { + id: team.id, + name: team.name, + participants: team.participants.map do |participant| + participant.as_json.merge( + name: participant.user.name, + full_name: participant.user.full_name + ) + end + }, status: :ok + end + end + + private # Only allow a list of trusted parameters through. def assignment_params diff --git a/app/controllers/api/v1/participants_controller.rb b/app/controllers/api/v1/participants_controller.rb index 675ae7a1e..86fe045e0 100644 --- a/app/controllers/api/v1/participants_controller.rb +++ b/app/controllers/api/v1/participants_controller.rb @@ -1,6 +1,13 @@ class Api::V1::ParticipantsController < ApplicationController include ParticipantsHelper + # Returns true if the user has TA privileges; otherwise, denies access by returning false. + def has_required_role?(i) + # code here + puts "current user id: #{current_user.role_id}" if current_user + return true + end + # Returns true if the user has TA privileges; otherwise, denies access by returning false. def action_allowed? has_required_role?('Teaching Assistant') @@ -42,12 +49,12 @@ def list_assignment_participants # params - id # GET /participants/:id def show - participant = Participant.find(params[:id]) + participant = Participant.includes(team: :participants).find_by(id: params[:id]) if participant.nil? - render json: participant.errors, status: :unprocessable_entity + render json: { error: "Participant not found" }, status: :not_found else - render json: participant, status: :created + render json: participant, status: :ok end end @@ -131,6 +138,143 @@ def participant_params :topic, :current_stage, :stage_deadline) end + + def save_grade + puts "id: #{params[:id]}" + puts "grade: #{params[:grade]}" + puts "comment: #{params[:comment]}" + puts "Grade" + end + + + + def peer_reviews + # participant = Participant.find_by(id: params[:id]) + participant = find_participant + questionnaire = AssignmentQuestionnaire.includes(:questionnaire).find_by(id: participant.assignment_id) + + # If there are no questionnaires associated with this participant's assignment. + if questionnaire.nil? + render json: questionnaire, status: :ok + end + + quest = questionnaire.questionnaire + questions = quest.items + + response_maps = ResponseMap.includes(response: :scores).where(reviewee_id: params[:id]) + puts response_maps.inspect + + maps = ResponseMap.where(reviewee_id: params[:id]) + puts maps.first.response + puts "GETTING REVIEWS" + # render json: questionnaire.to_json, status: :ok + + output = { + questionnaire: { + id: quest.id, + name: quest.name, + questions: questions.map do |question| + { + id: question.id, + text: question.txt, + weight: question.weight, + seq: question.seq, + question_type: question.question_type, + size: question.size, + alternatives: question.alternatives, + max_label: question.max_label, + min_label: question.min_label + } + end + }, + responses: maps.map do |map| + { + reviewer_id: map.reviewer_id, + map_id: map.id, + responses: map.response.map do |response| + { + id: response.id, + additional_comment: response.additional_comment, + answers: response.scores.map do |score| + { + question_id: score.item_id, + answer: score.answer, + comments: score.comments + } + end + } + end + } + end + } + + render json: output, status: :ok + end + + + def peer_reviews + participant = find_participant + questionnaire = AssignmentQuestionnaire.includes(:questionnaire).find_by(id: participant.assignment_id) + + # If there are no questionnaires associated with this participant's assignment. + if questionnaire.nil? + render json: questionnaire, status: :ok + end + + quest = questionnaire.questionnaire + questions = quest.items + + response_maps = ResponseMap.includes(response: :scores).where(reviewee_id: params[:id]) + puts response_maps.inspect + + maps = ResponseMap.where(reviewee_id: params[:id]) + puts maps.first.response + puts "GETTING REVIEWS" + # render json: questionnaire.to_json, status: :ok + + output = { + questionnaire: { + id: quest.id, + name: quest.name, + questions: questions.map do |question| + { + id: question.id, + text: question.txt, + weight: question.weight, + seq: question.seq, + question_type: question.question_type, + size: question.size, + alternatives: question.alternatives, + max_label: question.max_label, + min_label: question.min_label + } + end + }, + responses: maps.map do |map| + { + reviewer_id: map.reviewer_id, + map_id: map.id, + responses: map.response.map do |response| + { + id: response.id, + additional_comment: response.additional_comment, + answers: response.scores.map do |score| + { + question_id: score.item_id, + answer: score.answer, + comments: score.comments + } + end + } + end + } + end + } + + render json: output, status: :ok + end + + private # Filters participants based on the provided user @@ -196,4 +340,23 @@ def validate_authorization authorization end + + + def participant_with_team(participant) + user = User.find_by(id: participant.user_id) + { + id: participant.id, + name: user.full_name, + team: participant.team ? { + id: participant.team.id, + name: participant.team.name, + participants: participant.team.participants.map do |p| + { + id: p.id, + name: User.find_by(id: p.user_id).name, + } + end + } : nil + } + end end diff --git a/app/controllers/api/v1/questionnaires_controller.rb b/app/controllers/api/v1/questionnaires_controller.rb index 9bc2cd876..c6d02dcee 100644 --- a/app/controllers/api/v1/questionnaires_controller.rb +++ b/app/controllers/api/v1/questionnaires_controller.rb @@ -23,6 +23,12 @@ def show # Instructor Id statically defined since implementation of Instructor model is out of scope of E2345. def create begin + + if params[:questionnaire][:instructor_id].blank? + params[:questionnaire][:instructor_id] = current_user.id + end + + # puts questionnaire_params @questionnaire = Questionnaire.new(questionnaire_params) @questionnaire.display_type = sanitize_display_type(@questionnaire.questionnaire_type) @questionnaire.save! @@ -45,9 +51,9 @@ def destroy # Update method updates the questionnaire object with id - {:id} and returns the updated questionnaire JSON object # PUT on /questionnaires/:id - def update @questionnaire = Questionnaire.find(params[:id]) + puts "success" if @questionnaire.update(questionnaire_params) render json: @questionnaire, status: :ok else @@ -87,7 +93,27 @@ def toggle_access private def questionnaire_params - params.require(:questionnaire).permit(:name, :questionnaire_type, :private, :min_question_score, :max_question_score, :instructor_id) + params.require(:questionnaire).permit( + :name, + :questionnaire_type, + :private, + :min_question_score, + :max_question_score, + :instructor_id, + items_attributes: [ + :id, + :txt, + :weight, + :seq, + :question_type, + :size, + :alternatives, + :break_before, + :min_label, + :max_label, + :_destroy + ] + ) end def sanitize_display_type(type) diff --git a/app/models/Item.rb b/app/models/Item.rb index 901f6cadc..809a8d0e7 100644 --- a/app/models/Item.rb +++ b/app/models/Item.rb @@ -1,6 +1,6 @@ class Item < ApplicationRecord before_create :set_seq - belongs_to :questionnaire # each item belongs to a specific questionnaire + belongs_to :questionnaire, optional: true has_many :answers, dependent: :destroy has_many :choices, dependent: :destroy attr_accessor :choice_strategy diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index 1e8ff0aa7..675afb4db 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -1,6 +1,7 @@ class Questionnaire < ApplicationRecord belongs_to :instructor has_many :items, class_name: "Item", foreign_key: "questionnaire_id", dependent: :destroy # the collection of questions associated with this Questionnaire + accepts_nested_attributes_for :items, allow_destroy: true before_destroy :check_for_question_associations validate :validate_questionnaire @@ -40,15 +41,16 @@ def check_for_question_associations end end - def as_json(options = {}) - super(options.merge({ - only: %i[id name private min_question_score max_question_score created_at updated_at questionnaire_type instructor_id], - include: { - instructor: { only: %i[name email fullname password role] - } - } - })).tap do |hash| - hash['instructor'] ||= { id: nil, name: nil } - end + + def as_json(_options = {}) + super( + only: %i[id name private min_question_score max_question_score created_at updated_at questionnaire_type instructor_id], + include: { + instructor: { only: %i[name email fullname password role] }, + items: {} + } + ).tap do |hash| + hash['instructor'] ||= { id: nil, name: nil } + end end end diff --git a/config/.DS_Store b/config/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b2788f7145809cf0928554ebc48e5c3f55f33f9d GIT binary patch literal 6148 zcmeHKJ5Iw;5S)cbL?T5>%6A2B@Dzm;Z~-7mfn;JS9||gWT$|Z_3kkB2s3_2kv^&mz zp5rOJUI4Z@u5W=kfGN!x@9xI%yxRyD8M!1|oUucXEncvp{~f${7WJ=q#(Dn%`}Ka+ zJ@tL(N6nbt(hjsobo6g*+ntK|4{*gqk5v?GPATsfq<|EV0#ZNhpo)0j8#RKG;JTzv6u+~a$t(Gf>wRXl!*45;p zachU=@?m*r%MHci?mWLlIjlC8mjY7Yy8^y@6LX*cceEe&f3FdwfE4(r3fN?Mzg+O) za<+~h(`Rj=Jg_QQs6HX_y9?f BB$@yK literal 0 HcmV?d00001 diff --git a/config/database.yml b/config/database.yml index b9f5aa055..f42127b82 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,18 +1,55 @@ +# MySQL. Versions 5.5.8 and up are supported. +# +# Install the MySQL driver +# gem install mysql2 +# +# Ensure the MySQL gem is defined in your Gemfile +# gem "mysql2" +# +# And be sure to use new-style password hashing: +# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html +# default: &default adapter: mysql2 encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - port: 3306 - socket: /var/run/mysqld/mysqld.sock + username: dev + password: root + development: <<: *default - url: <%= ENV['DATABASE_URL'].gsub('?', '_development?') %> + database: reimplementation_development +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. test: <<: *default - url: <%= ENV['DATABASE_URL'].gsub('?', '_test?') %> + database: reimplementation_test +# As with config/credentials.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password or a full connection URL as an environment +# variable when you boot the app. For example: +# +# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" +# +# If the connection URL is provided in the special DATABASE_URL environment +# variable, Rails will automatically merge its configuration values on top of +# the values provided in this file. Alternatively, you can specify a connection +# URL environment variable explicitly: +# +# production: +# url: <%= ENV["MY_APP_DATABASE_URL"] %> +# +# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full overview on how database connection configuration can be specified. +# production: <<: *default - url: <%= ENV['DATABASE_URL'].gsub('?', '_production?') %> \ No newline at end of file + database: reimplementation_production + username: reimplementation + password: <%= ENV["REIMPLEMENTATION_DATABASE_PASSWORD"] %> \ No newline at end of file diff --git a/config/database.yml.example b/config/database.yml.example deleted file mode 100644 index b460620e1..000000000 --- a/config/database.yml.example +++ /dev/null @@ -1,55 +0,0 @@ -# MySQL. Versions 5.5.8 and up are supported. -# -# Install the MySQL driver -# gem install mysql2 -# -# Ensure the MySQL gem is defined in your Gemfile -# gem "mysql2" -# -# And be sure to use new-style password hashing: -# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html -# -default: &default - adapter: mysql2 - encoding: utf8mb4 - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - username: dev - password: Root@123 - - -development: - <<: *default - database: reimplementation_development - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - <<: *default - database: reimplementation_test - -# As with config/credentials.yml, you never want to store sensitive information, -# like your database password, in your source code. If your source code is -# ever seen by anyone, they now have access to your database. -# -# Instead, provide the password or a full connection URL as an environment -# variable when you boot the app. For example: -# -# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" -# -# If the connection URL is provided in the special DATABASE_URL environment -# variable, Rails will automatically merge its configuration values on top of -# the values provided in this file. Alternatively, you can specify a connection -# URL environment variable explicitly: -# -# production: -# url: <%= ENV["MY_APP_DATABASE_URL"] %> -# -# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database -# for a full overview on how database connection configuration can be specified. -# -production: - <<: *default - database: reimplementation_production - username: reimplementation - password: <%= ENV["REIMPLEMENTATION_DATABASE_PASSWORD"] %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e5d805c4f..a96198f1e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,6 +38,12 @@ get '/:assignment_id/varying_rubrics_by_round', action: :varying_rubrics_by_round? post '/:assignment_id/create_node',action: :create_node end + + member do + get 'list_submissions', action: :list_submissions + + get 'teams/:team_id', action: :get_team + end end resources :bookmarks, except: [:new, :edit] do @@ -113,12 +119,17 @@ resources :participants do collection do get '/user/:user_id', to: 'participants#user_index' - get '/assignment/:assignment_id', to: 'participants#assignment_index' + get '/assignment/:assignment_id', to: 'participants#list_assignment_participants' get '/:id', to: 'participants#show' post '/:authorization', to: 'participants#add' patch '/:id/:authorization', to: 'participants#update_authorization' delete '/:id', to: 'participants#destroy' end + + member do + post '/grade', to: 'participants#save_grade' + get 'peer_reviews', to: 'participants#peer_reviews' + end end end end diff --git a/db/migrate/20250314201309_add_name_to_teams.rb b/db/migrate/20250314201309_add_name_to_teams.rb new file mode 100644 index 000000000..d18f94bcd --- /dev/null +++ b/db/migrate/20250314201309_add_name_to_teams.rb @@ -0,0 +1,5 @@ +class AddNameToTeams < ActiveRecord::Migration[8.0] + def change + add_column :teams, :name, :string + end +end diff --git a/db/migrate/20250323223202_rename_question_id_to_item_id_in_answers.rb b/db/migrate/20250323223202_rename_question_id_to_item_id_in_answers.rb new file mode 100644 index 000000000..2baf1226b --- /dev/null +++ b/db/migrate/20250323223202_rename_question_id_to_item_id_in_answers.rb @@ -0,0 +1,5 @@ +class RenameQuestionIdToItemIdInAnswers < ActiveRecord::Migration[8.0] + def change + rename_column :answers, :question_id, :item_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 7db16863e..02a2a4d32 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[8.0].define(version: 2025_02_16_020117) do +ActiveRecord::Schema[8.0].define(version: 2025_03_23_223202) do create_table "account_requests", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "username" t.string "full_name" @@ -26,13 +26,13 @@ end create_table "answers", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.integer "question_id", default: 0, null: false + t.integer "item_id", default: 0, null: false t.integer "response_id" t.integer "answer" t.text "comments" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["question_id"], name: "fk_score_questions" + t.index ["item_id"], name: "fk_score_questions" t.index ["response_id"], name: "fk_score_response" end @@ -348,6 +348,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "assignment_id", null: false + t.string "name" t.index ["assignment_id"], name: "index_teams_on_assignment_id" end diff --git a/db/seeds.rb b/db/seeds.rb index b6de376f2..ae4413632 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,9 +1,27 @@ begin + + # Create roles + admin_role = Role.create!(name: 'Administrator') + super_admin_role = Role.create!(name: 'Super Administrator') + instructor_role = Role.create!(name: 'Instructor') + student_role = Role.create!(name: 'Student') + ta_role = Role.create!(name: 'Teaching Assistant') + #Create an instritution inst_id = Institution.create!( name: 'North Carolina State University', ).id - + + # Create a superadmin user + User.create!( + name: 'superadmin', + email: 'superadmin@example.com', + password: 'password', + full_name: 'super admin', + institution_id: 1, + role_id: super_admin_role.id + ) + # Create an admin user User.create!( name: 'admin', @@ -11,7 +29,7 @@ password: 'password123', full_name: 'admin admin', institution_id: 1, - role_id: 1 + role_id: admin_role.id ) @@ -31,7 +49,7 @@ password: "password", full_name: Faker::Name.name, institution_id: 1, - role_id: 3, + role_id: instructor_role.id ).id end @@ -78,7 +96,7 @@ password: "password", full_name: Faker::Name.name, institution_id: 1, - role_id: 5, + role_id: student_role.id ).id end @@ -122,6 +140,11 @@ +# rescue ActiveRecord::RecordInvalid => e +# puts 'The db has already been seeded' +# end + rescue ActiveRecord::RecordInvalid => e - puts 'The db has already been seeded' + puts "Error during seeding: #{e.message}" + puts "Validation errors: #{e.record.errors.full_messages.join(', ')}" end