class V1::MatchesController
Controller for matches
-
Renders a list of all matches
-
Renders one particular match
-
Creates a new match
-
Updates a match
-
Deletes a match
-
Serializes a Match using V1::MatchSerializer
Public Instance Methods
Create a match
-
Request
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
Delete a match
-
Params
-
:id
- id of a Match
-
-
Response
-
:no_content
or HTTP error
-
# File app/controllers/v1/matches_controller.rb, line 87 def destroy @match.destroy head :no_content end
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
Update a match
-
Params
-
:id
- id of a Match
-
-
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