From e88201aa891163916d4616eb42480d2ad8851097 Mon Sep 17 00:00:00 2001 From: Just Me Date: Sat, 2 Sep 2023 16:40:31 +0300 Subject: [PATCH] Add API for judges list --- app/channels/api_channel.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/channels/api_channel.rb b/app/channels/api_channel.rb index c33a19de..c061ddff 100644 --- a/app/channels/api_channel.rb +++ b/app/channels/api_channel.rb @@ -6,6 +6,7 @@ def subscribed 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 '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 @@ -39,6 +40,28 @@ def delete_criterion data dispatch_all 'criteria/delete', data['id'] end + def add_judge data + return unless scoring_open data + + task = Task.find task_id + task.judges << data['value'] + task.save! + dispatch_all 'judges/load', task.judges + end + + def delete_judge data + return unless scoring_open data + + task = Task.find task_id + if task.judges[data['index']] == data['value'] + task.judges.delete_at data['index'] + task.save! + dispatch_all 'judges/load', task.judges + else + dispatch_self 'errors/push', "Delete failed: Judge #{data['index']} has changed" + end + end + def drag_drop data return unless scoring_open data