class V1::TeamsController
Controller for teams
-
Renders a list of all teams
-
Renders a particular team
-
Creates a new team
-
Updates a team
-
Deletes a team
Teams can not be deleted if they are in a match
Public Instance Methods
Create a team
-
Request
-
:name
- team name -
:first_player_id
- first player on team -
:second_player_id
- second player on team
-
-
Response
# File app/controllers/v1/teams_controller.rb, line 41 def create json = team_params json[:doubles] = true @team = Team.new(json) if @team.save render json: @team, status: :created, location: @team else render json: {errors: @team.errors}, status: :unprocessable_entity end end
Delete a team A team in a match may not be deleted
-
Params
-
:id
- team id
-
-
Response
-
:no_content
or HTTP error
-
# File app/controllers/v1/teams_controller.rb, line 77 def destroy if @team.destroy head :no_content else render json: {errors: @team.errors}, status: :unprocessable_entity end end
Get a list of all doubles teams, sorted by team name. Singles teams are for internal use so are not shown to end users.
-
Response
-
List of teams
-
# File app/controllers/v1/teams_controller.rb, line 20 def index @teams = Team.where(doubles: true).order 'lower(name)' render json: @teams, serializer: V1::ApplicationArraySerializer end
Get a particular team
-
Params
-
:id
- team id
-
-
Response
# File app/controllers/v1/teams_controller.rb, line 30 def show render json: @team end
Update a team
-
Params
-
:id
- team id
-
-
Request
-
:name
- different team name -
:first_player_id
- different first player -
:second_player_id
- different second player
-
-
Response
-
Team or HTTP error
-
# File app/controllers/v1/teams_controller.rb, line 62 def update if @team.update(team_params) render json: @team, status: :ok else render json: {errors: @team.errors}, status: :unprocessable_entity end end