diff --git a/src/ttt/application/game/common/ports/game_views.py b/src/ttt/application/game/common/ports/game_views.py index 3f4ebe0..1c6f5a2 100644 --- a/src/ttt/application/game/common/ports/game_views.py +++ b/src/ttt/application/game/common/ports/game_views.py @@ -7,7 +7,7 @@ class GameViews(ABC): @abstractmethod - async def render_game_view_with_locations( + async def game_view_with_locations( self, user_locations: Sequence[UserGameLocation], game: Game, @@ -15,7 +15,7 @@ async def render_game_view_with_locations( ) -> None: ... @abstractmethod - async def render_started_game_view_with_locations( + async def started_game_view_with_locations( self, user_locations: Sequence[UserGameLocation], game: Game, @@ -23,14 +23,14 @@ async def render_started_game_view_with_locations( ) -> None: ... @abstractmethod - async def render_no_game_view( + async def no_game_view( self, user_location: UserLocation, /, ) -> None: ... @abstractmethod - async def render_game_already_complteted_view( + async def game_already_complteted_view( self, user_location: UserLocation, game: Game, @@ -38,7 +38,7 @@ async def render_game_already_complteted_view( ) -> None: ... @abstractmethod - async def render_not_current_user_view( + async def not_current_user_view( self, user_location: UserLocation, game: Game, @@ -46,7 +46,7 @@ async def render_not_current_user_view( ) -> None: ... @abstractmethod - async def render_no_cell_view( + async def no_cell_view( self, user_location: UserLocation, game: Game, @@ -54,7 +54,7 @@ async def render_no_cell_view( ) -> None: ... @abstractmethod - async def render_already_filled_cell_error( + async def already_filled_cell_error( self, user_location: UserLocation, game: Game, @@ -62,28 +62,28 @@ async def render_already_filled_cell_error( ) -> None: ... @abstractmethod - async def render_user_already_in_game_views( + async def user_already_in_game_views( self, locations: Sequence[UserLocation], /, ) -> None: ... @abstractmethod - async def render_waiting_for_game_view( + async def waiting_for_game_view( self, location: UserLocation, /, ) -> None: ... @abstractmethod - async def render_double_waiting_for_game_view( + async def double_waiting_for_game_view( self, location: UserLocation, /, ) -> None: ... @abstractmethod - async def render_waiting_for_ai_type_to_start_game_with_ai_view( + async def waiting_for_ai_type_to_start_game_with_ai_view( self, location: UserLocation, /, diff --git a/src/ttt/application/game/game/cancel_game.py b/src/ttt/application/game/game/cancel_game.py index 4ad5006..092effd 100644 --- a/src/ttt/application/game/game/cancel_game.py +++ b/src/ttt/application/game/game/cancel_game.py @@ -30,7 +30,7 @@ async def __call__(self, location: UserLocation) -> None: self.uuids.random_uuid(), ) if game is None: - await self.game_views.render_no_game_view(location) + await self.game_views.no_game_view(location) return locations = tuple( @@ -47,7 +47,7 @@ async def __call__(self, location: UserLocation) -> None: game, location, ) - await self.game_views.render_game_already_complteted_view( + await self.game_views.game_already_complteted_view( location, game, ) @@ -56,7 +56,7 @@ async def __call__(self, location: UserLocation) -> None: await self.log.game_cancelled(location, game) await self.map_(tracking) - await self.game_views.render_game_view_with_locations( + await self.game_views.game_view_with_locations( locations, game, ) diff --git a/src/ttt/application/game/game/make_move_in_game.py b/src/ttt/application/game/game/make_move_in_game.py index 101c21b..2b6293b 100644 --- a/src/ttt/application/game/game/make_move_in_game.py +++ b/src/ttt/application/game/game/make_move_in_game.py @@ -43,7 +43,7 @@ async def __call__( game = await self.games.game_with_game_location(location.user_id) if game is None: - await self.game_views.render_no_game_view(location) + await self.game_views.no_game_view(location) return locations = tuple( @@ -71,7 +71,7 @@ async def __call__( location, cell_number_int, ) - await self.game_views.render_game_already_complteted_view( + await self.game_views.game_already_complteted_view( location, game, ) @@ -81,7 +81,7 @@ async def __call__( location, cell_number_int, ) - await self.game_views.render_not_current_user_view( + await self.game_views.not_current_user_view( location, game, ) @@ -91,14 +91,14 @@ async def __call__( location, cell_number_int, ) - await self.game_views.render_no_cell_view(location, game) + await self.game_views.no_cell_view(location, game) except AlreadyFilledCellError: await self.log.already_filled_cell_to_make_move( game, location, cell_number_int, ) - await self.game_views.render_already_filled_cell_error( + await self.game_views.already_filled_cell_error( location, game, ) @@ -106,7 +106,7 @@ async def __call__( await self.log.user_move_maked(location, game, user_move) if user_move.next_move_ai_id is not None: - await self.game_views.render_game_view_with_locations( + await self.game_views.game_view_with_locations( locations, game, ) @@ -137,7 +137,7 @@ async def __call__( await self.log.game_completed(location, game) await self.map_(tracking) - await self.game_views.render_game_view_with_locations( + await self.game_views.game_view_with_locations( locations, game, ) diff --git a/src/ttt/application/game/game/start_game.py b/src/ttt/application/game/game/start_game.py index 18a00e6..532a347 100644 --- a/src/ttt/application/game/game/start_game.py +++ b/src/ttt/application/game/game/start_game.py @@ -9,7 +9,7 @@ from ttt.application.game.common.ports.games import Games from ttt.application.game.common.ports.waiting_locations import WaitingLocations from ttt.application.game.game.ports.game_log import GameLog -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.entities.core.game.game import UsersAlreadyInGameError, start_game from ttt.entities.core.user.location import UserLocation @@ -22,7 +22,7 @@ class StartGame: uuids: UUIDs emojis: Emojis users: Users - user_views: UserViews + user_views: CommonUserViews games: Games game_views: GameViews waiting_locations: WaitingLocations @@ -55,11 +55,11 @@ async def __call__(self) -> None: ) if user1 is None: - await self.user_views.render_user_is_not_registered_view( + await self.user_views.user_is_not_registered_view( user1_location, ) if user2 is None: - await self.user_views.render_user_is_not_registered_view( + await self.user_views.user_is_not_registered_view( user2_location, ) if user1 is None or user2 is None: @@ -112,7 +112,7 @@ async def __call__(self) -> None: await self.waiting_locations.push_many( locations_of_users_not_in_game, ) - await self.game_views.render_user_already_in_game_views( + await self.game_views.user_already_in_game_views( locations_of_users_in_game, ) continue @@ -125,9 +125,7 @@ async def __call__(self) -> None: user1_location.game(game.id), user2_location.game(game.id), ) - await ( - self.game_views.render_started_game_view_with_locations( - game_locations, - game, - ) + await self.game_views.started_game_view_with_locations( + game_locations, + game, ) diff --git a/src/ttt/application/game/game/wait_game.py b/src/ttt/application/game/game/wait_game.py index 484e221..5070602 100644 --- a/src/ttt/application/game/game/wait_game.py +++ b/src/ttt/application/game/game/wait_game.py @@ -4,7 +4,7 @@ from ttt.application.game.common.ports.game_views import GameViews from ttt.application.game.common.ports.waiting_locations import WaitingLocations from ttt.application.game.game.ports.game_log import GameLog -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.entities.core.user.location import UserLocation @@ -13,7 +13,7 @@ class WaitGame: users: Users waiting_locations: WaitingLocations - user_views: UserViews + user_views: CommonUserViews game_views: GameViews transaction: Transaction log: GameLog @@ -23,7 +23,7 @@ async def __call__(self, location: UserLocation) -> None: if not await self.users.contains_user_with_id( location.user_id, ): - await self.user_views.render_user_is_not_registered_view( + await self.user_views.user_is_not_registered_view( location, ) return @@ -32,9 +32,9 @@ async def __call__(self, location: UserLocation) -> None: if push.was_location_dedublicated: await self.log.double_waiting_for_game_start(location) - await self.game_views.render_double_waiting_for_game_view( + await self.game_views.double_waiting_for_game_view( location, ) else: await self.log.waiting_for_game_start(location) - await self.game_views.render_waiting_for_game_view(location) + await self.game_views.waiting_for_game_view(location) diff --git a/src/ttt/application/game/game_with_ai/start_game_with_ai.py b/src/ttt/application/game/game_with_ai/start_game_with_ai.py index 3110991..3d5d9ce 100644 --- a/src/ttt/application/game/game_with_ai/start_game_with_ai.py +++ b/src/ttt/application/game/game_with_ai/start_game_with_ai.py @@ -10,7 +10,7 @@ from ttt.application.game.common.ports.games import Games from ttt.application.game.common.ports.waiting_locations import WaitingLocations from ttt.application.game.game.ports.game_log import GameLog -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.entities.core.game.ai import AiType from ttt.entities.core.game.game import start_game_with_ai @@ -26,7 +26,7 @@ class StartGameWithAi: emojis: Emojis randoms: Randoms users: Users - user_views: UserViews + user_views: CommonUserViews games: Games game_views: GameViews waiting_locations: WaitingLocations @@ -46,7 +46,7 @@ async def __call__(self, location: UserLocation, ai_type: AiType) -> None: user = await self.users.user_with_id(location.user_id) if user is None: - await self.user_views.render_user_is_not_registered_view( + await self.user_views.user_is_not_registered_view( location, ) return @@ -70,7 +70,7 @@ async def __call__(self, location: UserLocation, ai_type: AiType) -> None: user, location, ) - await self.game_views.render_user_already_in_game_views( + await self.game_views.user_already_in_game_views( [location], ) else: @@ -78,18 +78,14 @@ async def __call__(self, location: UserLocation, ai_type: AiType) -> None: if started_game.next_move_ai_id is None: await self.map_(tracking) - await ( - self.game_views.render_started_game_view_with_locations( - [location.game(started_game.game.id)], - started_game.game, - ) + await self.game_views.started_game_view_with_locations( + [location.game(started_game.game.id)], + started_game.game, ) else: - await ( - self.game_views.render_started_game_view_with_locations( - [location.game(started_game.game.id)], - started_game.game, - ) + await self.game_views.started_game_view_with_locations( + [location.game(started_game.game.id)], + started_game.game, ) game_result_id = await self.uuids.random_uuid() @@ -114,7 +110,7 @@ async def __call__(self, location: UserLocation, ai_type: AiType) -> None: ) await self.map_(tracking) - await self.game_views.render_game_view_with_locations( + await self.game_views.game_view_with_locations( [location.game(started_game.game.id)], started_game.game, ) diff --git a/src/ttt/application/game/game_with_ai/wait_ai_type_to_start_game_with_ai.py b/src/ttt/application/game/game_with_ai/wait_ai_type_to_start_game_with_ai.py index 3c02531..3999812 100644 --- a/src/ttt/application/game/game_with_ai/wait_ai_type_to_start_game_with_ai.py +++ b/src/ttt/application/game/game_with_ai/wait_ai_type_to_start_game_with_ai.py @@ -11,8 +11,7 @@ class WaitAiTypeToStartGameWithAi: log: GameLog async def __call__(self, location: UserLocation) -> None: - await ( - self.game_views - .render_waiting_for_ai_type_to_start_game_with_ai_view(location) + await self.game_views.waiting_for_ai_type_to_start_game_with_ai_view( + location, ) await self.log.user_intends_to_start_game_against_ai(location) diff --git a/src/ttt/application/user/common/ports/user_views.py b/src/ttt/application/user/common/ports/user_views.py index 5f3155e..f5700fd 100644 --- a/src/ttt/application/user/common/ports/user_views.py +++ b/src/ttt/application/user/common/ports/user_views.py @@ -1,130 +1,40 @@ from abc import ABC, abstractmethod -from uuid import UUID -from ttt.entities.core.stars import Stars from ttt.entities.core.user.location import UserLocation -from ttt.entities.core.user.user import User -class UserViews(ABC): +class CommonUserViews(ABC): @abstractmethod - async def render_view_of_user_with_id( + async def view_of_user_with_id( self, location: UserLocation, /, ) -> None: ... @abstractmethod - async def render_user_is_not_registered_view( + async def user_is_not_registered_view( self, location: UserLocation, /, ) -> None: ... @abstractmethod - async def render_user_already_registered_view( + async def user_already_registered_view( self, location: UserLocation, /, ) -> None: ... @abstractmethod - async def render_user_registered_view( + async def user_registered_view( self, location: UserLocation, /, ) -> None: ... @abstractmethod - async def render_wait_emoji_to_buy_view( + async def selected_emoji_removed_view( self, location: UserLocation, /, ) -> None: ... - - @abstractmethod - async def render_not_enough_stars_to_buy_emoji_view( - self, - location: UserLocation, - stars_to_become_enough: Stars, - /, - ) -> None: ... - - @abstractmethod - async def render_emoji_already_purchased_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_emoji_was_purchased_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_invalid_emoji_to_buy_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_invalid_emoji_to_select_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_emoji_not_purchased_to_select_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_emoji_selected_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_selected_emoji_removed_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_wait_stars_to_start_stars_purshase_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_invalid_stars_for_stars_purchase_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_stars_purchase_will_be_completed_view( - self, - location: UserLocation, - /, - ) -> None: ... - - @abstractmethod - async def render_completed_stars_purshase_view( - self, - user: User, - purshase_id: UUID, - location: UserLocation, - /, - ) -> None: ... diff --git a/src/ttt/application/user/emoji_purchase/buy_emoji.py b/src/ttt/application/user/emoji_purchase/buy_emoji.py index 1b21d82..248bc79 100644 --- a/src/ttt/application/user/emoji_purchase/buy_emoji.py +++ b/src/ttt/application/user/emoji_purchase/buy_emoji.py @@ -9,11 +9,14 @@ UserFsm, WaitingEmojiToBuyState, ) -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.application.user.emoji_purchase.ports.user_log import ( EmojiPurchaseUserLog, ) +from ttt.application.user.emoji_purchase.ports.user_views import ( + EmojiPurchaseUserViews, +) from ttt.entities.core.user.location import UserLocation from ttt.entities.core.user.user import ( EmojiAlreadyPurchasedError, @@ -30,7 +33,8 @@ class BuyEmoji: clock: Clock transaction: Transaction users: Users - user_views: UserViews + common_views: CommonUserViews + emoji_purchase_views: EmojiPurchaseUserViews map_: Map log: EmojiPurchaseUserLog @@ -42,13 +46,17 @@ async def __call__( await self.fsm.state(WaitingEmojiToBuyState) if emoji_str is None: - await self.user_views.render_invalid_emoji_to_buy_view(location) + await self.emoji_purchase_views.invalid_emoji_to_buy_view( + location, + ) return try: emoji = Emoji(emoji_str) except InvalidEmojiError: - await self.user_views.render_invalid_emoji_to_buy_view(location) + await self.emoji_purchase_views.invalid_emoji_to_buy_view( + location, + ) return purchased_emoji_id, current_datetime = await gather( @@ -60,7 +68,7 @@ async def __call__( user = await self.users.user_with_id(location.user_id) if user is None: - await self.user_views.render_user_is_not_registered_view( + await self.common_views.user_is_not_registered_view( location, ) await self.fsm.set(None) @@ -81,20 +89,23 @@ async def __call__( emoji, ) await self.fsm.set(None) - await self.user_views.render_emoji_already_purchased_view( + await self.emoji_purchase_views.emoji_already_purchased_view( location, ) except NotEnoughStarsError as error: await self.fsm.set(None) - await self.user_views.render_not_enough_stars_to_buy_emoji_view( - location, - error.stars_to_become_enough, + await ( + self.emoji_purchase_views + .not_enough_stars_to_buy_emoji_view( + location, + error.stars_to_become_enough, + ) ) else: await self.log.user_bought_emoji(location, user, emoji) await self.map_(tracking) await self.fsm.set(None) - await self.user_views.render_emoji_was_purchased_view( + await self.emoji_purchase_views.emoji_was_purchased_view( location, ) diff --git a/src/ttt/application/user/emoji_purchase/ports/user_views.py b/src/ttt/application/user/emoji_purchase/ports/user_views.py new file mode 100644 index 0000000..bd31b9d --- /dev/null +++ b/src/ttt/application/user/emoji_purchase/ports/user_views.py @@ -0,0 +1,42 @@ +from abc import ABC, abstractmethod + +from ttt.entities.core.stars import Stars +from ttt.entities.core.user.location import UserLocation + + +class EmojiPurchaseUserViews(ABC): + @abstractmethod + async def wait_emoji_to_buy_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def not_enough_stars_to_buy_emoji_view( + self, + location: UserLocation, + stars_to_become_enough: Stars, + /, + ) -> None: ... + + @abstractmethod + async def emoji_already_purchased_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def emoji_was_purchased_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def invalid_emoji_to_buy_view( + self, + location: UserLocation, + /, + ) -> None: ... diff --git a/src/ttt/application/user/emoji_purchase/wait_emoji_to_buy.py b/src/ttt/application/user/emoji_purchase/wait_emoji_to_buy.py index 4c1137c..8d0d11d 100644 --- a/src/ttt/application/user/emoji_purchase/wait_emoji_to_buy.py +++ b/src/ttt/application/user/emoji_purchase/wait_emoji_to_buy.py @@ -5,22 +5,24 @@ UserFsm, WaitingEmojiToBuyState, ) -from ttt.application.user.common.ports.user_views import UserViews from ttt.application.user.emoji_purchase.ports.user_log import ( EmojiPurchaseUserLog, ) +from ttt.application.user.emoji_purchase.ports.user_views import ( + EmojiPurchaseUserViews, +) from ttt.entities.core.user.location import UserLocation @dataclass(frozen=True, unsafe_hash=False) class WaitEmojiToBuy: fsm: UserFsm - user_views: UserViews + user_views: EmojiPurchaseUserViews log: EmojiPurchaseUserLog async def __call__(self, location: UserLocation) -> None: await gather( self.fsm.set(WaitingEmojiToBuyState()), - self.user_views.render_wait_emoji_to_buy_view(location), + self.user_views.wait_emoji_to_buy_view(location), ) await self.log.user_intends_to_buy_emoji(location) diff --git a/src/ttt/application/user/emoji_selection/ports/user_views.py b/src/ttt/application/user/emoji_selection/ports/user_views.py new file mode 100644 index 0000000..ce8246f --- /dev/null +++ b/src/ttt/application/user/emoji_selection/ports/user_views.py @@ -0,0 +1,33 @@ +from abc import ABC, abstractmethod + +from ttt.entities.core.user.location import UserLocation + + +class EmojiSelectionUserViews(ABC): + @abstractmethod + async def invalid_emoji_to_select_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def emoji_not_purchased_to_select_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def emoji_selected_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def wait_emoji_to_select_view( + self, + location: UserLocation, + /, + ) -> None: ... diff --git a/src/ttt/application/user/emoji_selection/select_emoji.py b/src/ttt/application/user/emoji_selection/select_emoji.py index 3bb82a5..a1d2833 100644 --- a/src/ttt/application/user/emoji_selection/select_emoji.py +++ b/src/ttt/application/user/emoji_selection/select_emoji.py @@ -6,11 +6,14 @@ UserFsm, WaitingEmojiToSelectState, ) -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.application.user.emoji_selection.ports.user_log import ( EmojiSelectionUserLog, ) +from ttt.application.user.emoji_selection.ports.user_views import ( + EmojiSelectionUserViews, +) from ttt.entities.core.user.location import UserLocation from ttt.entities.core.user.user import EmojiNotPurchasedError from ttt.entities.text.emoji import Emoji, InvalidEmojiError @@ -22,7 +25,8 @@ class SelectEmoji: fsm: UserFsm transaction: Transaction users: Users - user_views: UserViews + user_views: CommonUserViews + emoji_selection_views: EmojiSelectionUserViews map_: Map log: EmojiSelectionUserLog @@ -34,7 +38,7 @@ async def __call__( await self.fsm.state(WaitingEmojiToSelectState) if emoji_str is None: - await self.user_views.render_invalid_emoji_to_select_view( + await self.emoji_selection_views.invalid_emoji_to_select_view( location, ) return @@ -42,8 +46,9 @@ async def __call__( try: emoji = Emoji(emoji_str) except InvalidEmojiError: - await self.user_views.render_invalid_emoji_to_select_view( - location, + await ( + self.emoji_selection_views + .invalid_emoji_to_select_view(location) ) return @@ -51,9 +56,7 @@ async def __call__( user = await self.users.user_with_id(location.user_id) if user is None: - await self.user_views.render_user_is_not_registered_view( - location, - ) + await self.user_views.user_is_not_registered_view(location) await self.fsm.set(None) return @@ -67,12 +70,13 @@ async def __call__( emoji, ) await self.fsm.set(None) - await self.user_views.render_emoji_not_purchased_to_select_view( - location, + await ( + self.emoji_selection_views + .emoji_not_purchased_to_select_view(location) ) else: await self.log.user_selected_emoji(location, user, emoji) await self.map_(tracking) await self.fsm.set(None) - await self.user_views.render_emoji_selected_view(location) + await self.emoji_selection_views.emoji_selected_view(location) diff --git a/src/ttt/application/user/emoji_selection/wait_emoji_to_select.py b/src/ttt/application/user/emoji_selection/wait_emoji_to_select.py index 10928b5..0e683e0 100644 --- a/src/ttt/application/user/emoji_selection/wait_emoji_to_select.py +++ b/src/ttt/application/user/emoji_selection/wait_emoji_to_select.py @@ -5,22 +5,24 @@ UserFsm, WaitingEmojiToSelectState, ) -from ttt.application.user.common.ports.user_views import UserViews from ttt.application.user.emoji_selection.ports.user_log import ( EmojiSelectionUserLog, ) +from ttt.application.user.emoji_selection.ports.user_views import ( + EmojiSelectionUserViews, +) from ttt.entities.core.user.location import UserLocation @dataclass(frozen=True, unsafe_hash=False) class WaitEmojiToSelect: fsm: UserFsm - user_views: UserViews + views: EmojiSelectionUserViews log: EmojiSelectionUserLog async def __call__(self, location: UserLocation) -> None: await gather( self.fsm.set(WaitingEmojiToSelectState()), - self.user_views.render_wait_emoji_to_buy_view(location), + self.views.wait_emoji_to_select_view(location), ) await self.log.user_intends_to_select_emoji(location) diff --git a/src/ttt/application/user/register_user.py b/src/ttt/application/user/register_user.py index a3fb8ac..0a80b68 100644 --- a/src/ttt/application/user/register_user.py +++ b/src/ttt/application/user/register_user.py @@ -3,7 +3,7 @@ from ttt.application.common.ports.map import Map, NotUniqueUserIdError from ttt.application.common.ports.transaction import Transaction from ttt.application.user.common.ports.user_log import CommonUserLog -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.entities.core.user.location import UserLocation from ttt.entities.core.user.user import register_user from ttt.entities.tools.tracking import Tracking @@ -12,7 +12,7 @@ @dataclass(frozen=True, unsafe_hash=False) class RegisterUser: transaction: Transaction - user_views: UserViews + views: CommonUserViews map_: Map log: CommonUserLog @@ -27,9 +27,7 @@ async def __call__(self, user_id: int, user_chat_id: int) -> None: await self.map_(tracking) except NotUniqueUserIdError: await self.log.user_double_registration(location, user) - await self.user_views.render_user_already_registered_view( - location, - ) + await self.views.user_already_registered_view(location) else: await self.log.user_registered(location, user) - await self.user_views.render_user_registered_view(location) + await self.views.user_registered_view(location) diff --git a/src/ttt/application/user/remove_emoji.py b/src/ttt/application/user/remove_emoji.py index b61a4db..86f546e 100644 --- a/src/ttt/application/user/remove_emoji.py +++ b/src/ttt/application/user/remove_emoji.py @@ -3,7 +3,7 @@ from ttt.application.common.ports.map import Map from ttt.application.common.ports.transaction import Transaction from ttt.application.user.common.ports.user_log import CommonUserLog -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.entities.core.user.location import UserLocation from ttt.entities.tools.tracking import Tracking @@ -13,7 +13,7 @@ class RemoveEmoji: transaction: Transaction users: Users - user_views: UserViews + views: CommonUserViews map_: Map log: CommonUserLog @@ -22,9 +22,7 @@ async def __call__(self, location: UserLocation) -> None: user = await self.users.user_with_id(location.user_id) if user is None: - await self.user_views.render_user_is_not_registered_view( - location, - ) + await self.views.user_is_not_registered_view(location) return tracking = Tracking() @@ -32,4 +30,4 @@ async def __call__(self, location: UserLocation) -> None: await self.log.user_removed_emoji(location, user) await self.map_(tracking) - await self.user_views.render_selected_emoji_removed_view(location) + await self.views.selected_emoji_removed_view(location) diff --git a/src/ttt/application/user/stars_purchase/complete_stars_purshase_payment.py b/src/ttt/application/user/stars_purchase/complete_stars_purshase_payment.py index 3b75ca3..a6dfc6d 100644 --- a/src/ttt/application/user/stars_purchase/complete_stars_purshase_payment.py +++ b/src/ttt/application/user/stars_purchase/complete_stars_purshase_payment.py @@ -6,11 +6,14 @@ from ttt.application.user.common.ports.paid_stars_purchase_payment_inbox import ( # noqa: E501 PaidStarsPurchasePaymentInbox, ) -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.application.user.stars_purchase.ports.user_log import ( StarsPurchaseUserLog, ) +from ttt.application.user.stars_purchase.ports.user_views import ( + StarsPurchaseUserViews, +) from ttt.entities.finance.payment.payment import PaymentIsNotInProcessError from ttt.entities.tools.tracking import Tracking @@ -22,7 +25,8 @@ class CompleteStarsPurshasePayment: users: Users transaction: Transaction map_: Map - user_views: UserViews + common_views: CommonUserViews + stars_purshase_views: StarsPurchaseUserViews log: StarsPurchaseUserLog async def __call__(self) -> None: @@ -35,7 +39,7 @@ async def __call__(self) -> None: ) if user is None: - await self.user_views.render_user_is_not_registered_view( + await self.common_views.user_is_not_registered_view( paid_payment.location, ) continue @@ -60,8 +64,10 @@ async def __call__(self) -> None: ) await self.map_(tracking) - await self.user_views.render_completed_stars_purshase_view( - user, - paid_payment.purshase_id, - paid_payment.location, + await ( + self.stars_purshase_views.completed_stars_purshase_view( + user, + paid_payment.purshase_id, + paid_payment.location, + ) ) diff --git a/src/ttt/application/user/stars_purchase/ports/user_views.py b/src/ttt/application/user/stars_purchase/ports/user_views.py new file mode 100644 index 0000000..a1f74aa --- /dev/null +++ b/src/ttt/application/user/stars_purchase/ports/user_views.py @@ -0,0 +1,37 @@ +from abc import ABC, abstractmethod +from uuid import UUID + +from ttt.entities.core.user.location import UserLocation +from ttt.entities.core.user.user import User + + +class StarsPurchaseUserViews(ABC): + @abstractmethod + async def wait_stars_to_start_stars_purshase_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def invalid_stars_for_stars_purchase_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def stars_purchase_will_be_completed_view( + self, + location: UserLocation, + /, + ) -> None: ... + + @abstractmethod + async def completed_stars_purshase_view( + self, + user: User, + purshase_id: UUID, + location: UserLocation, + /, + ) -> None: ... diff --git a/src/ttt/application/user/stars_purchase/start_stars_purchase.py b/src/ttt/application/user/stars_purchase/start_stars_purchase.py index 163da8f..e54a288 100644 --- a/src/ttt/application/user/stars_purchase/start_stars_purchase.py +++ b/src/ttt/application/user/stars_purchase/start_stars_purchase.py @@ -9,11 +9,14 @@ StarsPurchasePaymentGateway, ) from ttt.application.user.common.ports.user_fsm import UserFsm -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.common.ports.users import Users from ttt.application.user.stars_purchase.ports.user_log import ( StarsPurchaseUserLog, ) +from ttt.application.user.stars_purchase.ports.user_views import ( + StarsPurchaseUserViews, +) from ttt.entities.core.stars import Stars from ttt.entities.core.user.location import UserLocation from ttt.entities.core.user.stars_purchase import ( @@ -30,7 +33,8 @@ class StartStarsPurchase: users: Users uuids: UUIDs clock: Clock - user_views: UserViews + common_views: CommonUserViews + stars_purshase_views: StarsPurchaseUserViews payment_gateway: StarsPurchasePaymentGateway map_: Map log: StarsPurchaseUserLog @@ -43,7 +47,7 @@ async def __call__(self, location: UserLocation, stars: Stars) -> None: ) if user is None: - await self.user_views.render_user_is_not_registered_view( + await self.common_views.user_is_not_registered_view( location, ) await self.fsm.set(None) @@ -65,8 +69,8 @@ async def __call__(self, location: UserLocation, stars: Stars) -> None: ) await self.fsm.set(None) await ( - self.user_views - .render_invalid_stars_for_stars_purchase_view(location) + self.stars_purshase_views + .invalid_stars_for_stars_purchase_view(location) ) return diff --git a/src/ttt/application/user/stars_purchase/start_stars_purshase_payment_completion.py b/src/ttt/application/user/stars_purchase/start_stars_purshase_payment_completion.py index ef2e4ad..1e8cfce 100644 --- a/src/ttt/application/user/stars_purchase/start_stars_purshase_payment_completion.py +++ b/src/ttt/application/user/stars_purchase/start_stars_purshase_payment_completion.py @@ -6,23 +6,25 @@ from ttt.application.user.common.ports.stars_purchase_payment_gateway import ( StarsPurchasePaymentGateway, ) -from ttt.application.user.common.ports.user_views import UserViews from ttt.application.user.stars_purchase.ports.user_log import ( StarsPurchaseUserLog, ) +from ttt.application.user.stars_purchase.ports.user_views import ( + StarsPurchaseUserViews, +) @dataclass(frozen=True, unsafe_hash=False) class StartStarsPurshasePaymentCompletion: inbox: PaidStarsPurchasePaymentInbox payment_gateway: StarsPurchasePaymentGateway - user_views: UserViews + views: StarsPurchaseUserViews log: StarsPurchaseUserLog async def __call__(self) -> None: async for paid_payment in self.payment_gateway.paid_payment_stream(): await self.inbox.push(paid_payment) - await self.user_views.render_stars_purchase_will_be_completed_view( + await self.views.stars_purchase_will_be_completed_view( paid_payment.location, ) await self.log.stars_purshase_payment_completion_started( diff --git a/src/ttt/application/user/stars_purchase/wait_stars_to_start_stars_purshase.py b/src/ttt/application/user/stars_purchase/wait_stars_to_start_stars_purshase.py index a350575..c532621 100644 --- a/src/ttt/application/user/stars_purchase/wait_stars_to_start_stars_purshase.py +++ b/src/ttt/application/user/stars_purchase/wait_stars_to_start_stars_purshase.py @@ -1,21 +1,23 @@ from dataclasses import dataclass from ttt.application.user.common.ports.user_fsm import UserFsm -from ttt.application.user.common.ports.user_views import UserViews from ttt.application.user.stars_purchase.ports.user_log import ( StarsPurchaseUserLog, ) +from ttt.application.user.stars_purchase.ports.user_views import ( + StarsPurchaseUserViews, +) from ttt.entities.core.user.location import UserLocation @dataclass(frozen=True, unsafe_hash=False) class WaitStarsToStartStarsPurshase: fsm: UserFsm - user_views: UserViews + views: StarsPurchaseUserViews log: StarsPurchaseUserLog async def __call__(self, location: UserLocation) -> None: await self.log.user_intends_to_buy_stars(location) - await self.user_views.render_wait_stars_to_start_stars_purshase_view( + await self.views.wait_stars_to_start_stars_purshase_view( location, ) diff --git a/src/ttt/application/user/view_user.py b/src/ttt/application/user/view_user.py index e993d23..6d9143e 100644 --- a/src/ttt/application/user/view_user.py +++ b/src/ttt/application/user/view_user.py @@ -2,17 +2,17 @@ from ttt.application.common.ports.transaction import Transaction from ttt.application.user.common.ports.user_log import CommonUserLog -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.entities.core.user.location import UserLocation @dataclass(frozen=True, unsafe_hash=False) class ViewUser: - user_views: UserViews + views: CommonUserViews transaction: Transaction log: CommonUserLog async def __call__(self, location: UserLocation) -> None: async with self.transaction: - await self.user_views.render_view_of_user_with_id(location) + await self.views.view_of_user_with_id(location) await self.log.user_viewed(location) diff --git a/src/ttt/main/aiogram/di.py b/src/ttt/main/aiogram/di.py index 89bf869..ff547fd 100755 --- a/src/ttt/main/aiogram/di.py +++ b/src/ttt/main/aiogram/di.py @@ -36,11 +36,17 @@ StarsPurchasePaymentGateway, ) from ttt.application.user.common.ports.user_fsm import UserFsm -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews from ttt.application.user.emoji_purchase.buy_emoji import BuyEmoji +from ttt.application.user.emoji_purchase.ports.user_views import ( + EmojiPurchaseUserViews, +) from ttt.application.user.emoji_purchase.wait_emoji_to_buy import ( WaitEmojiToBuy, ) +from ttt.application.user.emoji_selection.ports.user_views import ( + EmojiSelectionUserViews, +) from ttt.application.user.emoji_selection.select_emoji import SelectEmoji from ttt.application.user.emoji_selection.wait_emoji_to_select import ( WaitEmojiToSelect, @@ -50,6 +56,9 @@ from ttt.application.user.stars_purchase.complete_stars_purshase_payment import ( # noqa: E501 CompleteStarsPurshasePayment, ) +from ttt.application.user.stars_purchase.ports.user_views import ( + StarsPurchaseUserViews, +) from ttt.application.user.stars_purchase.start_stars_purchase import ( StartStarsPurchase, ) @@ -74,7 +83,10 @@ ) from ttt.presentation.adapters.user_fsm import AiogramTrustingUserFsm from ttt.presentation.adapters.user_views import ( - AiogramMessagesFromPostgresAsUserViews, + AiogramMessagesAsEmojiPurchaseUserViews, + AiogramMessagesAsEmojiSelectionUserViews, + AiogramMessagesAsStarsPurchaseUserViews, + AiogramMessagesFromPostgresAsCommonUserViews, ) from ttt.presentation.aiogram.common.bots import ttt_bot from ttt.presentation.aiogram.common.routes.all import common_routers @@ -129,10 +141,25 @@ async def provide_bot(self, secrets: Secrets) -> Bot: ) provide_user_views = provide( - AiogramMessagesFromPostgresAsUserViews, - provides=UserViews, + AiogramMessagesFromPostgresAsCommonUserViews, + provides=CommonUserViews, scope=Scope.REQUEST, ) + provide_stars_purchase_user_views = provide( + AiogramMessagesAsStarsPurchaseUserViews, + provides=StarsPurchaseUserViews, + scope=Scope.APP, + ) + provide_emoji_selection_user_views = provide( + AiogramMessagesAsEmojiSelectionUserViews, + provides=EmojiSelectionUserViews, + scope=Scope.APP, + ) + provide_emoji_purchase_user_views = provide( + AiogramMessagesAsEmojiPurchaseUserViews, + provides=EmojiPurchaseUserViews, + scope=Scope.APP, + ) @provide(scope=Scope.APP) def provide_stars_purchase_payment_gateway( diff --git a/src/ttt/presentation/adapters/game_views.py b/src/ttt/presentation/adapters/game_views.py index 9954be1..0190ef2 100644 --- a/src/ttt/presentation/adapters/game_views.py +++ b/src/ttt/presentation/adapters/game_views.py @@ -30,7 +30,7 @@ class BackroundAiogramMessagesAsGameViews(GameViews): _bot: Bot _storage: BaseStorage - async def render_game_view_with_locations( + async def game_view_with_locations( self, user_locations: Sequence[UserGameLocation], game: Game, @@ -48,7 +48,7 @@ async def render_game_view_with_locations( game, ) - async def render_started_game_view_with_locations( + async def started_game_view_with_locations( self, user_locations: Sequence[UserGameLocation], game: Game, @@ -64,7 +64,7 @@ async def render_started_game_view_with_locations( ), ) - async def render_no_game_view( + async def no_game_view( self, user_location: UserLocation, /, @@ -73,7 +73,7 @@ async def render_no_game_view( no_game_message(self._bot, user_location.chat_id), ) - async def render_not_current_user_view( + async def not_current_user_view( self, user_location: UserLocation, game: Game, @@ -83,7 +83,7 @@ async def render_not_current_user_view( not_current_user_message(self._bot, user_location.chat_id), ) - async def render_no_cell_view( + async def no_cell_view( self, user_location: UserLocation, game: Game, @@ -93,7 +93,7 @@ async def render_no_cell_view( no_cell_message(self._bot, user_location.chat_id), ) - async def render_already_filled_cell_error( + async def already_filled_cell_error( self, user_location: UserLocation, game: Game, @@ -103,7 +103,7 @@ async def render_already_filled_cell_error( already_filled_cell_message(self._bot, user_location.chat_id), ) - async def render_game_already_complteted_view( + async def game_already_complteted_view( self, user_location: UserLocation, game: Game, @@ -113,7 +113,7 @@ async def render_game_already_complteted_view( already_completed_game_message(self._bot, user_location.chat_id), ) - async def render_user_already_in_game_views( + async def user_already_in_game_views( self, locations: Sequence[UserLocation], ) -> None: @@ -122,7 +122,7 @@ async def render_user_already_in_game_views( user_already_in_game_message(self._bot, location.chat_id), ) - async def render_waiting_for_game_view( + async def waiting_for_game_view( self, location: UserLocation, ) -> None: @@ -130,7 +130,7 @@ async def render_waiting_for_game_view( waiting_for_game_message(self._bot, location.chat_id), ) - async def render_waiting_for_ai_type_to_start_game_with_ai_view( + async def waiting_for_ai_type_to_start_game_with_ai_view( self, location: UserLocation, ) -> None: @@ -138,7 +138,7 @@ async def render_waiting_for_ai_type_to_start_game_with_ai_view( message_to_start_game_with_ai(self._bot, location.chat_id), ) - async def render_double_waiting_for_game_view( + async def double_waiting_for_game_view( self, location: UserLocation, ) -> None: diff --git a/src/ttt/presentation/adapters/user_views.py b/src/ttt/presentation/adapters/user_views.py index 6764528..f457504 100644 --- a/src/ttt/presentation/adapters/user_views.py +++ b/src/ttt/presentation/adapters/user_views.py @@ -5,7 +5,16 @@ from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession -from ttt.application.user.common.ports.user_views import UserViews +from ttt.application.user.common.ports.user_views import CommonUserViews +from ttt.application.user.emoji_purchase.ports.user_views import ( + EmojiPurchaseUserViews, +) +from ttt.application.user.emoji_selection.ports.user_views import ( + EmojiSelectionUserViews, +) +from ttt.application.user.stars_purchase.ports.user_views import ( + StarsPurchaseUserViews, +) from ttt.entities.core.stars import Stars from ttt.entities.core.user.location import UserLocation from ttt.entities.core.user.user import User @@ -25,17 +34,17 @@ selected_emoji_removed_message, stars_added_message, stars_will_be_added_message, - wait_emoji_to_buy_message, + wait_emoji_message, wait_stars_to_start_stars_purshase_message, ) @dataclass(frozen=True, unsafe_hash=False) -class AiogramMessagesFromPostgresAsUserViews(UserViews): +class AiogramMessagesFromPostgresAsCommonUserViews(CommonUserViews): _bot: Bot _session: AsyncSession - async def render_view_of_user_with_id( + async def view_of_user_with_id( self, location: UserLocation, /, @@ -84,121 +93,143 @@ async def render_view_of_user_with_id( user_row.is_in_game, ) - async def render_user_registered_view( + async def user_registered_view( self, location: UserLocation, ) -> None: await help_message(self._bot, location.chat_id) - async def render_user_is_not_registered_view( + async def user_is_not_registered_view( self, location: UserLocation, ) -> None: await need_to_start_message(self._bot, location.chat_id) - async def render_user_already_registered_view( + async def user_already_registered_view( self, location: UserLocation, ) -> None: await help_message(self._bot, location.chat_id) - async def render_wait_emoji_to_buy_view( + async def selected_emoji_removed_view( self, location: UserLocation, /, ) -> None: - await wait_emoji_to_buy_message(self._bot, location.chat_id) + await selected_emoji_removed_message(self._bot, location.chat_id) + + +@dataclass(frozen=True, unsafe_hash=False) +class AiogramMessagesAsStarsPurchaseUserViews(StarsPurchaseUserViews): + _bot: Bot - async def render_not_enough_stars_to_buy_emoji_view( + async def wait_stars_to_start_stars_purshase_view( self, location: UserLocation, - stars_to_become_enough: Stars, /, ) -> None: - await not_enough_stars_to_buy_emoji_message( + await wait_stars_to_start_stars_purshase_message( self._bot, location.chat_id, - stars_to_become_enough, ) - async def render_emoji_already_purchased_view( + async def invalid_stars_for_stars_purchase_view( self, location: UserLocation, /, ) -> None: - await emoji_already_purchased_message(self._bot, location.chat_id) + raise NotImplementedError - async def render_emoji_was_purchased_view( + async def stars_purchase_will_be_completed_view( self, location: UserLocation, /, ) -> None: - await emoji_was_purchased_message(self._bot, location.chat_id) + await stars_will_be_added_message(self._bot, location.chat_id) - async def render_invalid_emoji_to_buy_view( + async def completed_stars_purshase_view( self, + user: User, + purshase_id: UUID, location: UserLocation, /, ) -> None: - await invalid_emoji_message(self._bot, location.chat_id) + await stars_added_message(self._bot, location.chat_id) + + +@dataclass(frozen=True, unsafe_hash=False) +class AiogramMessagesAsEmojiSelectionUserViews(EmojiSelectionUserViews): + _bot: Bot - async def render_invalid_emoji_to_select_view( + async def invalid_emoji_to_select_view( self, location: UserLocation, /, ) -> None: await invalid_emoji_message(self._bot, location.chat_id) - async def render_emoji_not_purchased_to_select_view( + async def emoji_not_purchased_to_select_view( self, location: UserLocation, /, ) -> None: await emoji_not_purchased_to_select_message(self._bot, location.chat_id) - async def render_emoji_selected_view( + async def emoji_selected_view( self, location: UserLocation, /, ) -> None: await emoji_selected_message(self._bot, location.chat_id) - async def render_selected_emoji_removed_view( + async def wait_emoji_to_select_view( self, location: UserLocation, /, ) -> None: - await selected_emoji_removed_message(self._bot, location.chat_id) + await wait_emoji_message(self._bot, location.chat_id) + + +@dataclass(frozen=True, unsafe_hash=False) +class AiogramMessagesAsEmojiPurchaseUserViews(EmojiPurchaseUserViews): + _bot: Bot - async def render_wait_stars_to_start_stars_purshase_view( + async def wait_emoji_to_buy_view( self, location: UserLocation, /, ) -> None: - await wait_stars_to_start_stars_purshase_message( + await wait_emoji_message(self._bot, location.chat_id) + + async def not_enough_stars_to_buy_emoji_view( + self, + location: UserLocation, + stars_to_become_enough: Stars, + /, + ) -> None: + await not_enough_stars_to_buy_emoji_message( self._bot, location.chat_id, + stars_to_become_enough, ) - async def render_invalid_stars_for_stars_purchase_view( + async def emoji_already_purchased_view( self, location: UserLocation, /, ) -> None: - raise NotImplementedError + await emoji_already_purchased_message(self._bot, location.chat_id) - async def render_stars_purchase_will_be_completed_view( + async def emoji_was_purchased_view( self, location: UserLocation, /, ) -> None: - await stars_will_be_added_message(self._bot, location.chat_id) + await emoji_was_purchased_message(self._bot, location.chat_id) - async def render_completed_stars_purshase_view( + async def invalid_emoji_to_buy_view( self, - user: User, - purshase_id: UUID, location: UserLocation, /, ) -> None: - await stars_added_message(self._bot, location.chat_id) + await invalid_emoji_message(self._bot, location.chat_id) diff --git a/src/ttt/presentation/aiogram/user/messages.py b/src/ttt/presentation/aiogram/user/messages.py index d635bb0..85b399d 100644 --- a/src/ttt/presentation/aiogram/user/messages.py +++ b/src/ttt/presentation/aiogram/user/messages.py @@ -58,7 +58,7 @@ async def profile_message( # noqa: PLR0913, PLR0917 await bot.send_message(chat_id, **content.as_kwargs()) -async def wait_emoji_to_buy_message(bot: Bot, chat_id: int) -> None: +async def wait_emoji_message(bot: Bot, chat_id: int) -> None: await bot.send_message(chat_id, "🎭 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ эмодТи")