From a6b7a905a0d9f20abcad8d1b60d3028ab1156322 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 25 Oct 2019 23:49:27 +0200 Subject: [PATCH] Return matches as children of tournament --- app/controllers/matches_controller.rb | 10 ++++++++++ config/routes.rb | 1 + 2 files changed, 11 insertions(+) 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]