diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 778fca9..f3918c6 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -4,6 +4,12 @@ class MatchesController < ApplicationController before_action :set_match, only: %i[show update] before_action :validate_params, only: %i[update] before_action -> { require_owner! @match.owner }, only: %i[update] + before_action :set_tournament, only: %i[index] + + # GET/tournaments/1/matches + def index + render json: @tournament.matches, each_serializer: MatchSerializer + end # GET /matches/1 def show @@ -61,6 +67,10 @@ class MatchesController < ApplicationController @match = Match.find(params[:id]) end + def set_tournament + @tournament = Tournament.find(params[:tournament_id]) + end + def match_params params.slice(:state).permit! end diff --git a/config/routes.rb b/config/routes.rb index 61901bd..143d90c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,7 @@ Rails.application.routes.draw do resources :teams, only: %i[show update] resources :tournaments do resources :statistics, only: %i[index] + resources :matches, only: %i[index] end resources :match_scores, only: %i[show update] resources :groups, only: %i[show]