Skip to content

Commit

Permalink
Adjust match change endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanB committed Sep 13, 2024
1 parent ceebecf commit bb45242
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions change_match_game_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def change_match_game_modes(matches):
}
payload = {"matches": matches}

response = requests.patch(url, json=payload, headers=headers)
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Error changing match game modes: Status code {response.status_code}")
print(f"Response content: {response.text}")
return None

if __name__ == "__main__":
new_mode = prompt("Enter the new game mode: ", validator=GameModeValidator())
match_range = prompt("Enter the range of matches to change (e.g., 1-5): ", validator=MatchRangeValidator())
Expand Down
14 changes: 7 additions & 7 deletions ranked/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ def get_all_users(request: Request) -> Response:

return Response(users_data)

@api_view(['PATCH'])
@api_view(['POST'])
def change_match_game_modes(request: Request) -> Response:
"""
Changes the game mode of the most recent match for each specified game mode.
Changes the game mode of specified matches.
"""
if request.META.get('HTTP_X_API_KEY') != API_KEY:
return Response(status=401, data={
Expand All @@ -417,14 +417,14 @@ def change_match_game_modes(request: Request) -> Response:

results = []
for match_data in request.data['matches']:
if 'old_game_mode' not in match_data or 'new_game_mode' not in match_data:
results.append({'error': 'Invalid match data format. Expected old_game_mode and new_game_mode.'})
if 'new_game_mode' not in match_data or 'match_number' not in match_data:
results.append({'error': 'Invalid match data format. Expected new_game_mode and match_number.'})
continue

try:
old_game_mode = GameMode.objects.get(short_code=match_data['old_game_mode'])
except GameMode.DoesNotExist:
results.append({'error': f"Game mode {match_data['old_game_mode']} does not exist."})
match = Match.objects.get(match_number=match_data['match_number'])
except Match.DoesNotExist:
results.append({'error': f"Match {match_data['match_number']} does not exist."})
continue

try:
Expand Down

0 comments on commit bb45242

Please sign in to comment.