88from ttt .application .common .ports .uuids import UUIDs
99from ttt .application .game .ports .game_views import GameViews
1010from ttt .application .game .ports .games import Games
11+ from ttt .entities .core .game .cell import AlreadyFilledCellError
12+ from ttt .entities .core .game .game import (
13+ AlreadyCompletedGameError ,
14+ NoCellError ,
15+ NotCurrentPlayerError ,
16+ )
1117from ttt .entities .core .player .location import PlayerLocation
1218from ttt .entities .math .vector import Vector
1319from ttt .entities .tools .assertion import not_none
@@ -29,22 +35,13 @@ async def __call__(
2935 location : PlayerLocation ,
3036 cell_position : Vector ,
3137 ) -> None :
32- """
33- :raises ttt.application.common.ports.players.NoPlayerWithIDError:
34- :raises ttt.application.game.ports.games.NoGameError:
35- :raises ttt.entities.core.game.game.AlreadyCompletedGameError:
36- :raises ttt.entities.core.game.game.NotCurrentPlayerError:
37- :raises ttt.entities.core.game.game.NoCellError:
38- :raises ttt.entities.core.game.cell.AlreadyFilledCellError:
39- """
40-
4138 async with self .transaction :
42- player = await self .players . player_with_id (location .player_id )
43- game = await self . games . game_with_id (
44- None
45- if player . game_location is None
46- else player . game_location . game_id ,
47- )
39+ game = await self .games . game_with_game_location (location .player_id )
40+
41+ if game is None :
42+ await self . game_views . render_no_game_view ( location )
43+ return
44+
4845 locations = tuple (
4946 not_none (player .game_location )
5047 for player in (game .player1 , game .player2 )
@@ -54,12 +51,31 @@ async def __call__(
5451 self .randoms .random (),
5552 )
5653
57- tracking = Tracking ()
58- game .make_move (
59- player .id , cell_position , game_result_id , random , tracking ,
60- )
61-
62- await self .map_ (tracking )
63- await self .game_views .render_game_view_with_locations (
64- locations , game ,
65- )
54+ try :
55+ tracking = Tracking ()
56+ game .make_move (
57+ location .player_id ,
58+ cell_position ,
59+ game_result_id ,
60+ random ,
61+ tracking ,
62+ )
63+ except AlreadyCompletedGameError :
64+ await self .game_views .render_game_already_complteted_view (
65+ location , game ,
66+ )
67+ except NotCurrentPlayerError :
68+ await self .game_views .render_not_current_player_view (
69+ location , game ,
70+ )
71+ except NoCellError :
72+ await self .game_views .render_no_cell_view (location , game )
73+ except AlreadyFilledCellError :
74+ await self .game_views .render_already_filled_cell_error (
75+ location , game ,
76+ )
77+ else :
78+ await self .map_ (tracking )
79+ await self .game_views .render_game_view_with_locations (
80+ locations , game ,
81+ )
0 commit comments