From 0cc366da723021615ef3fe7b2153afcee47f9b66 Mon Sep 17 00:00:00 2001 From: Just Me Date: Sun, 1 Oct 2023 01:35:38 +0300 Subject: [PATCH] Add result multiplier to tasks with API --- app/channels/api_channel.rb | 13 ++++++++++++- ...20230930203405_add_result_multiplier_to_tasks.rb | 5 +++++ db/structure.sql | 6 ++++-- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20230930203405_add_result_multiplier_to_tasks.rb diff --git a/app/channels/api_channel.rb b/app/channels/api_channel.rb index c061ddff..32206129 100644 --- a/app/channels/api_channel.rb +++ b/app/channels/api_channel.rb @@ -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 @@ -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 diff --git a/db/migrate/20230930203405_add_result_multiplier_to_tasks.rb b/db/migrate/20230930203405_add_result_multiplier_to_tasks.rb new file mode 100644 index 00000000..3be23ef9 --- /dev/null +++ b/db/migrate/20230930203405_add_result_multiplier_to_tasks.rb @@ -0,0 +1,5 @@ +class AddResultMultiplierToTasks < ActiveRecord::Migration[7.0] + def change + add_column :tasks, :result_multiplier, :string, default: '1', null: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 531ba4ce..612b5e7f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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 ); @@ -919,6 +920,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230630172057'), ('20230902145307'), ('20230902145308'), -('20230902145309'); +('20230902145309'), +('20230930203405');