class V1::TeamsController

Controller for teams

Teams can not be deleted if they are in a match

Public Instance Methods

create() click to toggle source

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
destroy() click to toggle source

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
index() click to toggle source

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
show() click to toggle source

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() click to toggle source

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