Return 404 on game event listing if the game not exists
This commit is contained in:
@@ -33,7 +33,13 @@ class GameSingleResource(APIView):
|
||||
class GameEventResource(APIView):
|
||||
def get(self, request, game_id):
|
||||
""" 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)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
15
game/game.py
15
game/game.py
@@ -72,24 +72,21 @@ class Minesweeper:
|
||||
|
||||
def is_mine(self, row, col):
|
||||
""" Checks whether the given location have a mine """
|
||||
try:
|
||||
return self.board[row][col] == -1
|
||||
except IndexError:
|
||||
if not self.is_point_in_board(row, col):
|
||||
return False
|
||||
return self.board[row][col] == -1
|
||||
|
||||
def is_empty(self, row, col):
|
||||
""" Checks whether the given location is empty """
|
||||
try:
|
||||
return self.board[row][col] == 0
|
||||
except IndexError:
|
||||
if not self.is_point_in_board(row, col):
|
||||
return False
|
||||
return self.board[row][col] == 0
|
||||
|
||||
def is_point(self, row, col):
|
||||
""" Checks whether the given location have pontuation """
|
||||
try:
|
||||
return self.board[row][col] > 0
|
||||
except IndexError:
|
||||
if not self.is_point_in_board(row, col):
|
||||
return False
|
||||
return self.board[row][col] > 0
|
||||
|
||||
def is_point_in_board(self, row, col):
|
||||
""" Checks whether the location is inside board """
|
||||
|
||||
Reference in New Issue
Block a user