Implement type parameter for tournaments index
This commit is contained in:
parent
6d40d091a4
commit
2b72d0457e
|
|
@ -9,7 +9,16 @@ class TournamentsController < ApplicationController
|
||||||
|
|
||||||
# GET /tournaments
|
# GET /tournaments
|
||||||
def index
|
def index
|
||||||
tournaments = Tournament.where(public: true).or(Tournament.where(owner: current_user)).order(:created_at)
|
type = index_params.fetch(:type, 'public')
|
||||||
|
if type == 'public'
|
||||||
|
tournaments = Tournament.where(public: true).order(:created_at)
|
||||||
|
elsif type == 'private'
|
||||||
|
tournaments = Tournament.where(owner: current_user, public: false).order(:created_at)
|
||||||
|
else
|
||||||
|
# invalid type specified
|
||||||
|
render json: { error: 'invalid type' }, status: :bad_request
|
||||||
|
return
|
||||||
|
end
|
||||||
render json: tournaments, each_serializer: SimpleTournamentSerializer
|
render json: tournaments, each_serializer: SimpleTournamentSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -69,6 +78,10 @@ class TournamentsController < ApplicationController
|
||||||
@tournament = Tournament.find(params[:id])
|
@tournament = Tournament.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def index_params
|
||||||
|
params.permit(:type)
|
||||||
|
end
|
||||||
|
|
||||||
def tournament_params
|
def tournament_params
|
||||||
params.slice(:name, :description, :public, :teams).permit!
|
params.slice(:name, :description, :public, :teams).permit!
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue