Return 404 on game event listing if the game not exists

This commit is contained in:
2020-11-08 14:24:13 -03:00
parent 92268557b7
commit 7ca3f9e189
2 changed files with 13 additions and 10 deletions

View File

@@ -33,7 +33,13 @@ class GameSingleResource(APIView):
class GameEventResource(APIView): class GameEventResource(APIView):
def get(self, request, game_id): def get(self, request, game_id):
""" Returns a list of all game events """ """ Returns a list of all game events """
events = GameEvent.objects.filter(game_id=game_id)
try:
game = Game.objects.get(pk=game_id)
except Game.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
events = GameEvent.objects.filter(game=game)
serializer = GameEventSerializer(events, many=True) serializer = GameEventSerializer(events, many=True)
return Response(serializer.data) return Response(serializer.data)

View File

@@ -72,24 +72,21 @@ class Minesweeper:
def is_mine(self, row, col): def is_mine(self, row, col):
""" Checks whether the given location have a mine """ """ Checks whether the given location have a mine """
try: if not self.is_point_in_board(row, col):
return self.board[row][col] == -1
except IndexError:
return False return False
return self.board[row][col] == -1
def is_empty(self, row, col): def is_empty(self, row, col):
""" Checks whether the given location is empty """ """ Checks whether the given location is empty """
try: if not self.is_point_in_board(row, col):
return self.board[row][col] == 0
except IndexError:
return False return False
return self.board[row][col] == 0
def is_point(self, row, col): def is_point(self, row, col):
""" Checks whether the given location have pontuation """ """ Checks whether the given location have pontuation """
try: if not self.is_point_in_board(row, col):
return self.board[row][col] > 0
except IndexError:
return False return False
return self.board[row][col] > 0
def is_point_in_board(self, row, col): def is_point_in_board(self, row, col):
""" Checks whether the location is inside board """ """ Checks whether the location is inside board """