From b001817bacf4e9f05312ba2cd727a7a1180067ea Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sat, 26 Oct 2019 00:34:04 +0200 Subject: [PATCH] Filter matches by state parameter --- app/controllers/matches_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index f3918c6..7c0c012 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -8,7 +8,14 @@ class MatchesController < ApplicationController # GET/tournaments/1/matches def index - render json: @tournament.matches, each_serializer: MatchSerializer + matches = if match_params['state'].nil? + @tournament.matches + else + @tournament.matches.select do |m| + m.state == match_params['state'] + end + end + render json: matches, each_serializer: MatchSerializer end # GET /matches/1