Implement PopulateMatchBelow Interactor & Organizer

This commit is contained in:
Daniel Schädler 2019-05-11 16:41:59 +02:00
parent d2f5d3594e
commit fc69c6e6e6
3 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class PopulateMatchBelowAndSave
include Interactor::Organizer
organize PopulateMatchBelow, SaveApplicationRecordObject
end