diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 5d225b7..dbfaabf 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -25,7 +25,11 @@ class TournamentsController < ApplicationController # GET /tournaments/1 def show - render json: @tournament, include: '**' + if show_params.fetch(:simple, 'false') == 'true' + render json: @tournament, serializer: SimpleTournamentSerializer + else + render json: @tournament, include: '**' + end end # POST /tournaments @@ -116,6 +120,10 @@ class TournamentsController < ApplicationController params.permit(:type) end + def show_params + params.permit(:simple) + end + def tournament_params params.slice(:name, :description, :public, :teams, :group_stage, :playoff_teams_amount).permit! end diff --git a/spec/controllers/tournaments_controller_spec.rb b/spec/controllers/tournaments_controller_spec.rb index cb1ef87..fade45b 100644 --- a/spec/controllers/tournaments_controller_spec.rb +++ b/spec/controllers/tournaments_controller_spec.rb @@ -102,6 +102,15 @@ RSpec.describe TournamentsController, type: :controller do get :show, params: { id: @tournament.to_param } expect(deserialize_response(response)[:id].to_i).to eq(@tournament.id) end + + context 'with simple=true parameter' do + it 'returns no relations' do + get :show, params: { id: @tournament.to_param, simple: 'true' } + body = deserialize_response response + expect(body[:stages]).to be_nil + expect(body[:teams]).to be_nil + end + end end describe 'POST #create' do