From fc69c6e6e611b2cb5deda05bb873f53453e773d2 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sat, 11 May 2019 16:41:59 +0200 Subject: [PATCH] Implement PopulateMatchBelow Interactor & Organizer --- app/controllers/matches_controller.rb | 2 +- app/interactors/populate_match_below.rb | 15 +++++++++++++++ app/organizers/populate_match_below_and_save.rb | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/interactors/populate_match_below.rb create mode 100644 app/organizers/populate_match_below_and_save.rb diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 1cfc05c..28ee8ed 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -14,7 +14,7 @@ class MatchesController < ApplicationController def update new_state = match_params['state'] if new_state == 'finished' - PlayoffStageService.populate_match_below(@match) unless @match.group_match? + PopulateMatchBelowAndSave.call(match:@match) unless @match.group_match? end if @match.update(match_params) render json: @match diff --git a/app/interactors/populate_match_below.rb b/app/interactors/populate_match_below.rb new file mode 100644 index 0000000..55539f0 --- /dev/null +++ b/app/interactors/populate_match_below.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class PopulateMatchBelow + include Interactor + + def call + match = context.match + begin + PlayoffStageService.populate_match_below(match) + context.object_to_save = match + rescue StandardError + context.fail! + end + end +end diff --git a/app/organizers/populate_match_below_and_save.rb b/app/organizers/populate_match_below_and_save.rb new file mode 100644 index 0000000..e947b90 --- /dev/null +++ b/app/organizers/populate_match_below_and_save.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class PopulateMatchBelowAndSave + include Interactor::Organizer + + organize PopulateMatchBelow, SaveApplicationRecordObject +end