Add state to stage

This state is required to stop the group stage and trigger playoff
generation, it is (for now) irrelevant for anything other than that.
This commit is contained in:
Daniel Schädler 2019-06-06 14:06:53 +02:00
parent 0e52663d46
commit 155ce57723
5 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class Stage < ApplicationRecord class Stage < ApplicationRecord
enum state: %i[playoff_stage in_progress finished]
belongs_to :tournament belongs_to :tournament
has_many :matches, dependent: :destroy has_many :matches, dependent: :destroy
has_many :groups, dependent: :destroy has_many :groups, dependent: :destroy

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class StageSerializer < ApplicationSerializer class StageSerializer < ApplicationSerializer
attributes :level attributes :level, :state
has_many :matches has_many :matches
has_many :groups has_many :groups

View File

@ -9,7 +9,7 @@ class GroupStageService
raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 1).zero? raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 1).zero?
groups = groups.map(&method(:get_group_object_from)) groups = groups.map(&method(:get_group_object_from))
Stage.new level: -1, groups: groups Stage.new level: -1, groups: groups, state: :in_progress
end end
def get_group_object_from(team_array) def get_group_object_from(team_array)

View File

@ -61,6 +61,7 @@ class CreateSchema < ActiveRecord::Migration[5.2]
create_table :stages do |t| create_table :stages do |t|
t.integer :level t.integer :level
t.integer :state, default: 0
t.belongs_to :tournament, index: true, foreign_key: { on_delete: :cascade }, null: false t.belongs_to :tournament, index: true, foreign_key: { on_delete: :cascade }, null: false

View File

@ -5,6 +5,7 @@ FactoryBot.define do
tournament tournament
factory :group_stage do factory :group_stage do
level { -1 } level { -1 }
state { :in_progress }
transient do transient do
group_count { 4 } group_count { 4 }
match_factory { :group_match } match_factory { :group_match }