Generate controllers
This commit is contained in:
parent
1f910b8746
commit
1736fe9fce
|
|
@ -1,8 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MatchController < ApplicationController
|
||||
def get
|
||||
id = params[:id]
|
||||
Match
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
class MatchesController < ApplicationController
|
||||
before_action :set_match, only: [:show, :update, :destroy]
|
||||
|
||||
# GET /matches
|
||||
def index
|
||||
@matches = Match.all
|
||||
|
||||
render json: @matches
|
||||
end
|
||||
|
||||
# GET /matches/1
|
||||
def show
|
||||
render json: @match
|
||||
end
|
||||
|
||||
# POST /matches
|
||||
def create
|
||||
@match = Match.new(match_params)
|
||||
|
||||
if @match.save
|
||||
render json: @match, status: :created, location: @match
|
||||
else
|
||||
render json: @match.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /matches/1
|
||||
def update
|
||||
if @match.update(match_params)
|
||||
render json: @match
|
||||
else
|
||||
render json: @match.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /matches/1
|
||||
def destroy
|
||||
@match.destroy
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_match
|
||||
@match = Match.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def match_params
|
||||
params.fetch(:match, {})
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
class TeamsController < ApplicationController
|
||||
before_action :set_team, only: [:show, :update, :destroy]
|
||||
|
||||
# GET /teams
|
||||
def index
|
||||
@teams = Team.all
|
||||
|
||||
render json: @teams
|
||||
end
|
||||
|
||||
# GET /teams/1
|
||||
def show
|
||||
render json: @team
|
||||
end
|
||||
|
||||
# POST /teams
|
||||
def create
|
||||
@team = Team.new(team_params)
|
||||
|
||||
if @team.save
|
||||
render json: @team, status: :created, location: @team
|
||||
else
|
||||
render json: @team.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /teams/1
|
||||
def update
|
||||
if @team.update(team_params)
|
||||
render json: @team
|
||||
else
|
||||
render json: @team.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /teams/1
|
||||
def destroy
|
||||
@team.destroy
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_team
|
||||
@team = Team.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def team_params
|
||||
params.fetch(:team, {})
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
class TournamentsController < ApplicationController
|
||||
before_action :set_tournament, only: [:show, :update, :destroy]
|
||||
|
||||
# GET /tournaments
|
||||
def index
|
||||
@tournaments = Tournament.all
|
||||
|
||||
render json: @tournaments
|
||||
end
|
||||
|
||||
# GET /tournaments/1
|
||||
def show
|
||||
render json: @tournament
|
||||
end
|
||||
|
||||
# POST /tournaments
|
||||
def create
|
||||
@tournament = Tournament.new(tournament_params)
|
||||
|
||||
if @tournament.save
|
||||
render json: @tournament, status: :created, location: @tournament
|
||||
else
|
||||
render json: @tournament.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /tournaments/1
|
||||
def update
|
||||
if @tournament.update(tournament_params)
|
||||
render json: @tournament
|
||||
else
|
||||
render json: @tournament.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /tournaments/1
|
||||
def destroy
|
||||
@tournament.destroy
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_tournament
|
||||
@tournament = Tournament.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def tournament_params
|
||||
params.fetch(:tournament, {})
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
require 'test_helper'
|
||||
|
||||
class MatchesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@match = matches(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get matches_url, as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create match" do
|
||||
assert_difference('Match.count') do
|
||||
post matches_url, params: { match: { } }, as: :json
|
||||
end
|
||||
|
||||
assert_response 201
|
||||
end
|
||||
|
||||
test "should show match" do
|
||||
get match_url(@match), as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update match" do
|
||||
patch match_url(@match), params: { match: { } }, as: :json
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
test "should destroy match" do
|
||||
assert_difference('Match.count', -1) do
|
||||
delete match_url(@match), as: :json
|
||||
end
|
||||
|
||||
assert_response 204
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
require 'test_helper'
|
||||
|
||||
class TeamsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@team = teams(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get teams_url, as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create team" do
|
||||
assert_difference('Team.count') do
|
||||
post teams_url, params: { team: { } }, as: :json
|
||||
end
|
||||
|
||||
assert_response 201
|
||||
end
|
||||
|
||||
test "should show team" do
|
||||
get team_url(@team), as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update team" do
|
||||
patch team_url(@team), params: { team: { } }, as: :json
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
test "should destroy team" do
|
||||
assert_difference('Team.count', -1) do
|
||||
delete team_url(@team), as: :json
|
||||
end
|
||||
|
||||
assert_response 204
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
require 'test_helper'
|
||||
|
||||
class TournamentsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@tournament = tournaments(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get tournaments_url, as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create tournament" do
|
||||
assert_difference('Tournament.count') do
|
||||
post tournaments_url, params: { tournament: { } }, as: :json
|
||||
end
|
||||
|
||||
assert_response 201
|
||||
end
|
||||
|
||||
test "should show tournament" do
|
||||
get tournament_url(@tournament), as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update tournament" do
|
||||
patch tournament_url(@tournament), params: { tournament: { } }, as: :json
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
test "should destroy tournament" do
|
||||
assert_difference('Tournament.count', -1) do
|
||||
delete tournament_url(@tournament), as: :json
|
||||
end
|
||||
|
||||
assert_response 204
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue