Skip to content

Commit

Permalink
Add result multiplier to tasks with API
Browse files Browse the repository at this point in the history
  • Loading branch information
just806me committed Sep 30, 2023
1 parent 6f5965a commit 0cc366d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 12 additions & 1 deletion app/channels/api_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ class ApiChannel < ApplicationCable::Channel

def subscribed
ensure_confirmation_sent
task = Task.find task_id
dispatch_self 'app/start'
dispatch_self 'users/load', task_users.order(:judge_secret).pluck(:judge_secret)
dispatch_self 'criteria/load', task_criterions.order(:position)
dispatch_self 'judges/load', Task.find(task_id).judges
dispatch_self 'judges/load', task.judges
dispatch_self 'resultMultiplier/load', task.result_multiplier
dispatch_self 'results/load', CriterionUserResult.includes(:user).where(criterion: task_criterions)
dispatch_self 'comments/load', Comment.includes(:user).where(task_id:)
dispatch_self 'locks/load', RedisLockManager.all
Expand Down Expand Up @@ -62,6 +64,15 @@ def delete_judge data
end
end

def write_result_multiplier data
return unless scoring_open data

task = Task.find task_id
task.result_multiplier = data['value']
task.save!
dispatch_all 'resultMultiplier/load', task.result_multiplier
end

def drag_drop data
return unless scoring_open data

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230930203405_add_result_multiplier_to_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddResultMultiplierToTasks < ActiveRecord::Migration[7.0]
def change
add_column :tasks, :result_multiplier, :string, default: '1', null: false
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ CREATE TABLE public.tasks (
updated_at timestamp(6) without time zone NOT NULL,
criterions_count integer DEFAULT 0 NOT NULL,
scoring_open boolean DEFAULT true NOT NULL,
judges character varying[] DEFAULT '{}'::character varying[] NOT NULL
judges character varying[] DEFAULT '{}'::character varying[] NOT NULL,
result_multiplier character varying DEFAULT '1'::character varying NOT NULL
);


Expand Down Expand Up @@ -919,6 +920,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230630172057'),
('20230902145307'),
('20230902145308'),
('20230902145309');
('20230902145309'),
('20230930203405');


0 comments on commit 0cc366d

Please sign in to comment.