Added model and controller stub

This commit is contained in:
Absurdon 2017-05-01 16:57:32 +02:00
parent d3fdef95c4
commit 160fccd118
7 changed files with 66 additions and 1 deletions

View file

@ -0,0 +1,11 @@
class MatchProposalsController < ApplicationController
def index
end
def new
end
def create
end
end

View file

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

View file

@ -0,0 +1,2 @@
<h1>MatchProposals#show</h1>
<p>Find me in app/views/match_proposals/show.html.erb</p>

View file

@ -0,0 +1,2 @@
<h1>MatchProposals#new</h1>
<p>Find me in app/views/match_proposals/new.html.erb</p>

View file

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

View file

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

View file

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