diff --git a/app/controllers/match_proposals_controller.rb b/app/controllers/match_proposals_controller.rb new file mode 100644 index 0000000..6079786 --- /dev/null +++ b/app/controllers/match_proposals_controller.rb @@ -0,0 +1,11 @@ +class MatchProposalsController < ApplicationController + def index + + end + + def new + end + + def create + end +end diff --git a/app/models/match_proposal.rb b/app/models/match_proposal.rb new file mode 100644 index 0000000..c662420 --- /dev/null +++ b/app/models/match_proposal.rb @@ -0,0 +1,22 @@ +class MatchProposal < ActiveRecord::Base + + STATUS_PENDING = 0 + STATUS_REVOKED = 1 + STATUS_REJECTED = 2 + STATUS_ACCEPTED = 3 + + belongs_to :match + belongs_to :team + attr_accessible :proposed_time, :status + + validates_presence_of :match, :team, :proposed_time + + def can_create? (match, cuser) + match && cuser && cuser.team.is_leader?(cuser) && (match.of_team cuser.team) + end + + def can_destroy? + cuser && cuser.admin? + end + +end diff --git a/app/views/match_proposals/index.html.erb b/app/views/match_proposals/index.html.erb new file mode 100644 index 0000000..feb7985 --- /dev/null +++ b/app/views/match_proposals/index.html.erb @@ -0,0 +1,2 @@ +
Find me in app/views/match_proposals/show.html.erb
diff --git a/app/views/match_proposals/new.html.erb b/app/views/match_proposals/new.html.erb new file mode 100644 index 0000000..a67703b --- /dev/null +++ b/app/views/match_proposals/new.html.erb @@ -0,0 +1,2 @@ +Find me in app/views/match_proposals/new.html.erb
diff --git a/config/routes.rb b/config/routes.rb index c0c9665..1917806 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Ensl::Application.routes.draw do + %w(403 404 422 500).each do |code| get code, to: "errors#show", code: code end @@ -60,6 +61,7 @@ Ensl::Application.routes.draw do get "matches/ref/:id" => "matches#ref", as: :match_ref resources :matches do get :admin, to: "matches#admin", on: :collection + resources :match_proposals, path: "proposals", as: "proposals", only: [:index, :new, :create] end resources :maps diff --git a/db/migrate/20170501121908_create_match_proposals.rb b/db/migrate/20170501121908_create_match_proposals.rb new file mode 100644 index 0000000..3072119 --- /dev/null +++ b/db/migrate/20170501121908_create_match_proposals.rb @@ -0,0 +1,14 @@ +class CreateMatchProposals < ActiveRecord::Migration + def change + create_table :match_proposals do |t| + t.references :match + t.references :team + t.integer :status + t.datetime :proposed_time + + t.timestamps + end + add_index :match_proposals, :match_id + add_index :match_proposals, :team_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 649d7e2..2320ecd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20170304191254) do +ActiveRecord::Schema.define(:version => 20170501121908) do create_table "admin_requests", :force => true do |t| t.string "addr" @@ -432,6 +432,18 @@ ActiveRecord::Schema.define(:version => 20170304191254) do t.integer "category_id" end + create_table "match_proposals", :force => true do |t| + t.integer "match_id" + t.integer "team_id" + t.integer "status" + t.datetime "proposed_time" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "match_proposals", ["match_id"], :name => "index_match_proposals_on_match_id" + add_index "match_proposals", ["team_id"], :name => "index_match_proposals_on_team_id" + create_table "matchers", :force => true do |t| t.integer "match_id", :null => false t.integer "user_id", :null => false