From 2e336262aa2593326b018ad72e04f2efd0091e05 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 6 Jun 2019 14:06:53 +0200 Subject: [PATCH] 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. --- app/models/stage.rb | 2 ++ app/serializers/stage_serializer.rb | 2 +- app/services/group_stage_service.rb | 2 +- db/migrate/0000_create_schema.rb | 1 + spec/factories/stages.rb | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/stage.rb b/app/models/stage.rb index 9246352..1f36b21 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Stage < ApplicationRecord + enum state: %i[playoff_stage in_progress finished] + belongs_to :tournament has_many :matches, dependent: :destroy has_many :groups, dependent: :destroy diff --git a/app/serializers/stage_serializer.rb b/app/serializers/stage_serializer.rb index dc76a83..56cb6d0 100644 --- a/app/serializers/stage_serializer.rb +++ b/app/serializers/stage_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StageSerializer < ApplicationSerializer - attributes :level + attributes :level, :state has_many :matches has_many :groups diff --git a/app/services/group_stage_service.rb b/app/services/group_stage_service.rb index 592f6ad..504ff24 100644 --- a/app/services/group_stage_service.rb +++ b/app/services/group_stage_service.rb @@ -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? groups = groups.map(&method(:get_group_object_from)) - Stage.new level: -1, groups: groups + Stage.new level: -1, groups: groups, state: :in_progress end def get_group_object_from(team_array) diff --git a/db/migrate/0000_create_schema.rb b/db/migrate/0000_create_schema.rb index 390edfa..61bba1f 100644 --- a/db/migrate/0000_create_schema.rb +++ b/db/migrate/0000_create_schema.rb @@ -63,6 +63,7 @@ class CreateSchema < ActiveRecord::Migration[5.2] create_table :stages do |t| t.integer :level + t.integer :state, default: 0 t.belongs_to :tournament, index: true, foreign_key: { on_delete: :cascade }, null: false diff --git a/spec/factories/stages.rb b/spec/factories/stages.rb index c2d1e2b..8027cd7 100644 --- a/spec/factories/stages.rb +++ b/spec/factories/stages.rb @@ -5,6 +5,7 @@ FactoryBot.define do tournament factory :group_stage do level { -1 } + state { :in_progress } transient do group_count { 4 } match_factory { :group_match }