class V1::MatchesController

Controller for matches

Public Instance Methods

create() click to toggle source

Create a match

  • Request

    • :title - match title

    • :scoring - scoring kind

    • :doubles - true for doubles

    • :first_team_id - id of a Team

    • :second_team_id - id of a Team

    • :first_player_id - id of a Player

    • :second_player_id - id of a Player

Teams are for a doubles match. Players are for a singles match.

  • Response

    • serialized Match or HTTP error

# File app/controllers/v1/matches_controller.rb, line 45
def create
  @match = create_match
  if @match.save
    render json: @match, status: :created, location: @match
  else
    render json: { errors: @match.errors }, status: :unprocessable_entity
  end
end
destroy() click to toggle source

Delete a match

  • Params

  • Response

    • :no_content or HTTP error

# File app/controllers/v1/matches_controller.rb, line 87
def destroy
  @match.destroy
  head :no_content
end
index() click to toggle source

Get a list of all matches, sorted by match title

  • Response

    • Serialized array of matches

# File app/controllers/v1/matches_controller.rb, line 19
def index
  @matches = Match.order 'lower(title)'
  render json: @matches, serializer: V1::ApplicationArraySerializer
end
show() click to toggle source

Get a particular match

# File app/controllers/v1/matches_controller.rb, line 29
def show
  render json: @match
end
update() click to toggle source

Update a match

  • Params

  • Request

    • :title - change title

    • :scoring - change scoring kind

    • :doubles - change doubles

    • :first_team_id - change first team

    • :second_team_id - change second team

    • :first_player_id - change first player

    • :second_player_id - change second player

Teams are for a doubles match. Players are for a singles match.

  • Response

    • serialized Match or HTTP error

# File app/controllers/v1/matches_controller.rb, line 68
def update
  doubles = match_params_doubles?(@match.doubles)
  update_sym = if doubles
                 :update_doubles_match
               else
                 :update_singles_match
               end
  if send(update_sym, @match, match_params(doubles))
    render json: @match, status: :ok
  else
    render json: { errors: @match.errors }, status: :unprocessable_entity
  end
end