diff --git a/pyproject.toml b/pyproject.toml index 4249948..fad9d54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ build-backend = "hatchling.build" packages = ["src/ttt"] [project.scripts] -ttt = "ttt.main.aiogram_slim.__main__:main" +ttt = "ttt.main.aiogram_prod.__main__:main" ttt-dev = "ttt.main.aiogram_dev.__main__:main" [tool.uv] diff --git a/src/ttt/application/game/common/ports/waiting_locations.py b/src/ttt/application/game/common/ports/game_starting_queue.py similarity index 86% rename from src/ttt/application/game/common/ports/waiting_locations.py rename to src/ttt/application/game/common/ports/game_starting_queue.py index 33ccec2..ff943c2 100644 --- a/src/ttt/application/game/common/ports/waiting_locations.py +++ b/src/ttt/application/game/common/ports/game_starting_queue.py @@ -6,17 +6,17 @@ @dataclass(frozen=True) -class WaitingLocationsPush: +class GameStartingQueuePush: was_location_dedublicated: bool -class WaitingLocations(ABC): +class GameStartingQueue(ABC): @abstractmethod async def push( self, location: UserLocation, /, - ) -> WaitingLocationsPush: ... + ) -> GameStartingQueuePush: ... @abstractmethod async def push_many( 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 2b6293b..5fc863f 100644 --- a/src/ttt/application/game/game/make_move_in_game.py +++ b/src/ttt/application/game/game/make_move_in_game.py @@ -58,7 +58,7 @@ async def __call__( try: tracking = Tracking() - user_move = game.make_move( + user_move = game.make_user_move( location.user_id, cell_number_int, game_result_id, diff --git a/src/ttt/application/game/game/ports/game_log.py b/src/ttt/application/game/game/ports/game_log.py index aa9d303..fed2201 100644 --- a/src/ttt/application/game/game/ports/game_log.py +++ b/src/ttt/application/game/game/ports/game_log.py @@ -129,14 +129,14 @@ async def already_completed_game_to_cancel( ) -> None: ... @abstractmethod - async def users_already_in_game_to_start_game_via_matchmaking_queue( + async def users_already_in_game_to_start_game_via_game_starting_queue( self, locations_of_users_in_game: Sequence[UserLocation], /, ) -> None: ... @abstractmethod - async def bad_attempt_to_start_game_via_matchmaking_queue( + async def bad_attempt_to_start_game_via_game_starting_queue( self, locations_of_users_not_in_game: Sequence[UserLocation], /, diff --git a/src/ttt/application/game/game/start_game.py b/src/ttt/application/game/game/start_game.py index 532a347..725192e 100644 --- a/src/ttt/application/game/game/start_game.py +++ b/src/ttt/application/game/game/start_game.py @@ -5,9 +5,11 @@ from ttt.application.common.ports.map import Map from ttt.application.common.ports.transaction import Transaction from ttt.application.common.ports.uuids import UUIDs +from ttt.application.game.common.ports.game_starting_queue import ( + GameStartingQueue, +) from ttt.application.game.common.ports.game_views import GameViews 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 CommonUserViews from ttt.application.user.common.ports.users import Users @@ -25,12 +27,12 @@ class StartGame: user_views: CommonUserViews games: Games game_views: GameViews - waiting_locations: WaitingLocations + game_starting_queue: GameStartingQueue transaction: Transaction log: GameLog async def __call__(self) -> None: - async for user1_location, user2_location in self.waiting_locations: + async for user1_location, user2_location in self.game_starting_queue: async with self.transaction, self.emojis: user1, user2 = await self.users.users_with_ids( (user1_location.user_id, user2_location.user_id), @@ -63,7 +65,7 @@ async def __call__(self) -> None: user2_location, ) if user1 is None or user2 is None: - await self.waiting_locations.push_many( + await self.game_starting_queue.push_many( tuple( location for user, location in users_and_locations @@ -98,18 +100,18 @@ async def __call__(self) -> None: await ( self.log - .users_already_in_game_to_start_game_via_matchmaking_queue( + .users_already_in_game_to_start_game_via_game_starting_queue( locations_of_users_in_game, ) ) await ( self.log - .bad_attempt_to_start_game_via_matchmaking_queue( + .bad_attempt_to_start_game_via_game_starting_queue( locations_of_users_not_in_game, ) ) - await self.waiting_locations.push_many( + await self.game_starting_queue.push_many( locations_of_users_not_in_game, ) await self.game_views.user_already_in_game_views( diff --git a/src/ttt/application/game/game/wait_game.py b/src/ttt/application/game/game/wait_game.py index 5070602..589cffb 100644 --- a/src/ttt/application/game/game/wait_game.py +++ b/src/ttt/application/game/game/wait_game.py @@ -1,8 +1,10 @@ from dataclasses import dataclass from ttt.application.common.ports.transaction import Transaction +from ttt.application.game.common.ports.game_starting_queue import ( + GameStartingQueue, +) 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 CommonUserViews from ttt.application.user.common.ports.users import Users @@ -12,7 +14,7 @@ @dataclass(frozen=True, unsafe_hash=False) class WaitGame: users: Users - waiting_locations: WaitingLocations + game_starting_queue: GameStartingQueue user_views: CommonUserViews game_views: GameViews transaction: Transaction @@ -28,7 +30,7 @@ async def __call__(self, location: UserLocation) -> None: ) return - push = await self.waiting_locations.push(location) + push = await self.game_starting_queue.push(location) if push.was_location_dedublicated: await self.log.double_waiting_for_game_start(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 3d5d9ce..e636c9b 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 @@ -6,9 +6,11 @@ from ttt.application.common.ports.transaction import Transaction from ttt.application.common.ports.uuids import UUIDs from ttt.application.game.common.ports.game_ai_gateway import GameAiGateway +from ttt.application.game.common.ports.game_starting_queue import ( + GameStartingQueue, +) from ttt.application.game.common.ports.game_views import GameViews 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 CommonUserViews from ttt.application.user.common.ports.users import Users @@ -29,7 +31,7 @@ class StartGameWithAi: user_views: CommonUserViews games: Games game_views: GameViews - waiting_locations: WaitingLocations + game_starting_queue: GameStartingQueue transaction: Transaction ai_gateway: GameAiGateway log: GameLog diff --git a/src/ttt/application/user/common/dto/common.py b/src/ttt/application/user/common/dto/common.py index 9e368d7..d92045d 100644 --- a/src/ttt/application/user/common/dto/common.py +++ b/src/ttt/application/user/common/dto/common.py @@ -7,6 +7,6 @@ @dataclass(frozen=True) class PaidStarsPurchasePayment: - purshase_id: UUID + purchase_id: UUID location: UserLocation success: PaymentSuccess diff --git a/src/ttt/application/user/common/ports/stars_purchase_payment_gateway.py b/src/ttt/application/user/common/ports/stars_purchase_payment_gateway.py index ad957b8..11967c0 100644 --- a/src/ttt/application/user/common/ports/stars_purchase_payment_gateway.py +++ b/src/ttt/application/user/common/ports/stars_purchase_payment_gateway.py @@ -11,7 +11,7 @@ class StarsPurchasePaymentGateway(ABC): @abstractmethod async def send_invoice( self, - purshase: StarsPurchase, + purchase: StarsPurchase, location: UserLocation, ) -> None: ... diff --git a/src/ttt/application/user/stars_purchase/complete_stars_purshase_payment.py b/src/ttt/application/user/stars_purchase/complete_stars_purchase_payment.py similarity index 87% rename from src/ttt/application/user/stars_purchase/complete_stars_purshase_payment.py rename to src/ttt/application/user/stars_purchase/complete_stars_purchase_payment.py index a6dfc6d..8a02490 100644 --- a/src/ttt/application/user/stars_purchase/complete_stars_purshase_payment.py +++ b/src/ttt/application/user/stars_purchase/complete_stars_purchase_payment.py @@ -19,14 +19,14 @@ @dataclass(frozen=True, unsafe_hash=False) -class CompleteStarsPurshasePayment: +class CompleteStarsPurchasePayment: clock: Clock inbox: PaidStarsPurchasePaymentInbox users: Users transaction: Transaction map_: Map common_views: CommonUserViews - stars_purshase_views: StarsPurchaseUserViews + stars_purchase_views: StarsPurchaseUserViews log: StarsPurchaseUserLog async def __call__(self) -> None: @@ -47,7 +47,7 @@ async def __call__(self) -> None: tracking = Tracking() try: user.complete_stars_purchase_payment( - paid_payment.purshase_id, + paid_payment.purchase_id, paid_payment.success, current_datetime, tracking, @@ -58,16 +58,16 @@ async def __call__(self) -> None: paid_payment, ) else: - await self.log.stars_purshase_payment_completed( + await self.log.stars_purchase_payment_completed( user, paid_payment, ) await self.map_(tracking) await ( - self.stars_purshase_views.completed_stars_purshase_view( + self.stars_purchase_views.completed_stars_purchase_view( user, - paid_payment.purshase_id, + paid_payment.purchase_id, paid_payment.location, ) ) diff --git a/src/ttt/application/user/stars_purchase/ports/user_log.py b/src/ttt/application/user/stars_purchase/ports/user_log.py index 44da6b3..bf739f5 100644 --- a/src/ttt/application/user/stars_purchase/ports/user_log.py +++ b/src/ttt/application/user/stars_purchase/ports/user_log.py @@ -31,14 +31,14 @@ async def user_started_stars_puchase_payment( ) -> None: ... @abstractmethod - async def stars_purshase_payment_completion_started( + async def stars_purchase_payment_completion_started( self, payment: PaidStarsPurchasePayment, /, ) -> None: ... @abstractmethod - async def stars_purshase_payment_completed( + async def stars_purchase_payment_completed( self, user: User, payment: PaidStarsPurchasePayment, diff --git a/src/ttt/application/user/stars_purchase/ports/user_views.py b/src/ttt/application/user/stars_purchase/ports/user_views.py index a1f74aa..2459b1c 100644 --- a/src/ttt/application/user/stars_purchase/ports/user_views.py +++ b/src/ttt/application/user/stars_purchase/ports/user_views.py @@ -7,7 +7,7 @@ class StarsPurchaseUserViews(ABC): @abstractmethod - async def wait_stars_to_start_stars_purshase_view( + async def wait_stars_to_start_stars_purchase_view( self, location: UserLocation, /, @@ -28,10 +28,10 @@ async def stars_purchase_will_be_completed_view( ) -> None: ... @abstractmethod - async def completed_stars_purshase_view( + async def completed_stars_purchase_view( self, user: User, - purshase_id: UUID, + purchase_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 e54a288..ac2e8b4 100644 --- a/src/ttt/application/user/stars_purchase/start_stars_purchase.py +++ b/src/ttt/application/user/stars_purchase/start_stars_purchase.py @@ -34,7 +34,7 @@ class StartStarsPurchase: uuids: UUIDs clock: Clock common_views: CommonUserViews - stars_purshase_views: StarsPurchaseUserViews + stars_purchase_views: StarsPurchaseUserViews payment_gateway: StarsPurchasePaymentGateway map_: Map log: StarsPurchaseUserLog @@ -69,7 +69,7 @@ async def __call__(self, location: UserLocation, stars: Stars) -> None: ) await self.fsm.set(None) await ( - self.stars_purshase_views + self.stars_purchase_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_purchase_payment_completion.py similarity index 90% rename from src/ttt/application/user/stars_purchase/start_stars_purshase_payment_completion.py rename to src/ttt/application/user/stars_purchase/start_stars_purchase_payment_completion.py index 1e8cfce..28dd3b9 100644 --- a/src/ttt/application/user/stars_purchase/start_stars_purshase_payment_completion.py +++ b/src/ttt/application/user/stars_purchase/start_stars_purchase_payment_completion.py @@ -15,7 +15,7 @@ @dataclass(frozen=True, unsafe_hash=False) -class StartStarsPurshasePaymentCompletion: +class StartStarsPurchasePaymentCompletion: inbox: PaidStarsPurchasePaymentInbox payment_gateway: StarsPurchasePaymentGateway views: StarsPurchaseUserViews @@ -27,6 +27,6 @@ async def __call__(self) -> None: await self.views.stars_purchase_will_be_completed_view( paid_payment.location, ) - await self.log.stars_purshase_payment_completion_started( + await self.log.stars_purchase_payment_completion_started( paid_payment, ) 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_purchase.py similarity index 86% rename from src/ttt/application/user/stars_purchase/wait_stars_to_start_stars_purshase.py rename to src/ttt/application/user/stars_purchase/wait_stars_to_start_stars_purchase.py index c532621..464382a 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_purchase.py @@ -11,13 +11,13 @@ @dataclass(frozen=True, unsafe_hash=False) -class WaitStarsToStartStarsPurshase: +class WaitStarsToStartStarsPurchase: fsm: UserFsm views: StarsPurchaseUserViews log: StarsPurchaseUserLog async def __call__(self, location: UserLocation) -> None: await self.log.user_intends_to_buy_stars(location) - await self.views.wait_stars_to_start_stars_purshase_view( + await self.views.wait_stars_to_start_stars_purchase_view( location, ) diff --git a/src/ttt/entities/core/game/game.py b/src/ttt/entities/core/game/game.py index c84b5f0..2e745ca 100644 --- a/src/ttt/entities/core/game/game.py +++ b/src/ttt/entities/core/game/game.py @@ -187,7 +187,7 @@ def cancel( self.state = GameState.completed tracking.register_mutated(self) - def make_move( + def make_user_move( self, user_id: int, cell_number_int: int, diff --git a/src/ttt/infrastructure/adapters/game_log.py b/src/ttt/infrastructure/adapters/game_log.py index f6979d9..a278240 100644 --- a/src/ttt/infrastructure/adapters/game_log.py +++ b/src/ttt/infrastructure/adapters/game_log.py @@ -209,7 +209,7 @@ async def already_completed_game_to_cancel( game_id=game.id.hex, ) - async def users_already_in_game_to_start_game_via_matchmaking_queue( + async def users_already_in_game_to_start_game_via_game_starting_queue( self, locations_of_users_in_game: Sequence[UserLocation], /, @@ -217,7 +217,7 @@ async def users_already_in_game_to_start_game_via_matchmaking_queue( await gather( *( self._logger.awarning( - "user_already_in_game_to_start_game_via_matchmaking_queue", + "user_already_in_game_to_start_game_via_game_starting_queue", chat_id=location.chat_id, user_id=location.user_id, ) @@ -225,7 +225,7 @@ async def users_already_in_game_to_start_game_via_matchmaking_queue( ), ) - async def bad_attempt_to_start_game_via_matchmaking_queue( + async def bad_attempt_to_start_game_via_game_starting_queue( self, locations_of_users_not_in_game: Sequence[UserLocation], /, @@ -233,7 +233,7 @@ async def bad_attempt_to_start_game_via_matchmaking_queue( await gather( *( self._logger.awarning( - "bad_attempt_to_start_game_via_matchmaking_queue", + "bad_attempt_to_start_game_via_game_starting_queue", chat_id=location.chat_id, user_id=location.user_id, ) diff --git a/src/ttt/infrastructure/adapters/waiting_locations.py b/src/ttt/infrastructure/adapters/game_starting_queue.py similarity index 81% rename from src/ttt/infrastructure/adapters/waiting_locations.py rename to src/ttt/infrastructure/adapters/game_starting_queue.py index 72d5ee8..bac1094 100644 --- a/src/ttt/infrastructure/adapters/waiting_locations.py +++ b/src/ttt/infrastructure/adapters/game_starting_queue.py @@ -4,16 +4,16 @@ from pydantic import TypeAdapter -from ttt.application.game.common.ports.waiting_locations import ( - WaitingLocations, - WaitingLocationsPush, +from ttt.application.game.common.ports.game_starting_queue import ( + GameStartingQueue, + GameStartingQueuePush, ) from ttt.entities.core.user.location import UserLocation from ttt.infrastructure.redis.batches import InRedisFixedBatches @dataclass(frozen=True, unsafe_hash=False) -class InRedisFixedBatchesWaitingLocations(WaitingLocations): +class InRedisFixedBatchesWaitingLocations(GameStartingQueue): _batches: InRedisFixedBatches _adapter: ClassVar = TypeAdapter(UserLocation) @@ -22,11 +22,11 @@ async def push_many(self, locations: Sequence[UserLocation], /) -> None: if locations: await self._batches.add(map(self._bytes, locations)) - async def push(self, location: UserLocation, /) -> WaitingLocationsPush: + async def push(self, location: UserLocation, /) -> GameStartingQueuePush: push_code = await self._batches.add([self._bytes(location)]) was_location_added_in_set = bool(push_code) - return WaitingLocationsPush( + return GameStartingQueuePush( was_location_dedublicated=not was_location_added_in_set, ) diff --git a/src/ttt/infrastructure/adapters/user_log.py b/src/ttt/infrastructure/adapters/user_log.py index e140989..f799845 100644 --- a/src/ttt/infrastructure/adapters/user_log.py +++ b/src/ttt/infrastructure/adapters/user_log.py @@ -190,29 +190,29 @@ async def user_started_stars_puchase_payment( user_id=user.id, ) - async def stars_purshase_payment_completion_started( + async def stars_purchase_payment_completion_started( self, payment: PaidStarsPurchasePayment, /, ) -> None: await self._logger.ainfo( - "stars_purshase_payment_completion_started", + "stars_purchase_payment_completion_started", user_id=payment.location.user_id, chat_id=payment.location.chat_id, - purshase_id=payment.purshase_id.hex, + purchase_id=payment.purchase_id.hex, ) - async def stars_purshase_payment_completed( + async def stars_purchase_payment_completed( self, user: User, payment: PaidStarsPurchasePayment, /, ) -> None: await self._logger.ainfo( - "stars_purshase_payment_completed", + "stars_purchase_payment_completed", user_id=payment.location.user_id, chat_id=payment.location.chat_id, - purshase_id=payment.purshase_id.hex, + purchase_id=payment.purchase_id.hex, ) async def double_stars_purchase_payment_completion( @@ -224,7 +224,7 @@ async def double_stars_purchase_payment_completion( "double_stars_purchase_payment_completion", user_id=paid_payment.location.user_id, chat_id=paid_payment.location.chat_id, - purshase_id=paid_payment.purshase_id.hex, + purchase_id=paid_payment.purchase_id.hex, ) async def invalid_stars_for_stars_purchase( diff --git a/src/ttt/main/aiogram/di.py b/src/ttt/main/aiogram/di.py index ff547fd..4a0506d 100755 --- a/src/ttt/main/aiogram/di.py +++ b/src/ttt/main/aiogram/di.py @@ -53,8 +53,8 @@ ) from ttt.application.user.register_user import RegisterUser from ttt.application.user.remove_emoji import RemoveEmoji -from ttt.application.user.stars_purchase.complete_stars_purshase_payment import ( # noqa: E501 - CompleteStarsPurshasePayment, +from ttt.application.user.stars_purchase.complete_stars_purchase_payment import ( # noqa: E501 + CompleteStarsPurchasePayment, ) from ttt.application.user.stars_purchase.ports.user_views import ( StarsPurchaseUserViews, @@ -65,11 +65,11 @@ from ttt.application.user.stars_purchase.start_stars_purchase_payment import ( StartStarsPurchasePayment, ) -from ttt.application.user.stars_purchase.start_stars_purshase_payment_completion import ( # noqa: E501 - StartStarsPurshasePaymentCompletion, +from ttt.application.user.stars_purchase.start_stars_purchase_payment_completion import ( # noqa: E501 + StartStarsPurchasePaymentCompletion, ) -from ttt.application.user.stars_purchase.wait_stars_to_start_stars_purshase import ( # noqa: E501 - WaitStarsToStartStarsPurshase, +from ttt.application.user.stars_purchase.wait_stars_to_start_stars_purchase import ( # noqa: E501 + WaitStarsToStartStarsPurchase, ) from ttt.application.user.view_user import ViewUser from ttt.infrastructure.buffer import Buffer @@ -180,15 +180,15 @@ async def unkillable_tasks( self, logger: FilteringBoundLogger, start_game: StartGame, - start_stars_purshase_payment_completion: ( - StartStarsPurshasePaymentCompletion + start_stars_purchase_payment_completion: ( + StartStarsPurchasePaymentCompletion ), - complete_stars_purshase_payment: CompleteStarsPurshasePayment, + complete_stars_purchase_payment: CompleteStarsPurchasePayment, ) -> UnkillableTasks: tasks = UnkillableTasks(logger) tasks.add(start_game) - tasks.add(start_stars_purshase_payment_completion) - tasks.add(complete_stars_purshase_payment) + tasks.add(start_stars_purchase_payment_completion) + tasks.add(complete_stars_purchase_payment) return tasks @@ -257,8 +257,8 @@ class ApplicationWithAiogramRequestDataProvider(Provider): WaitEmojiToSelect, scope=Scope.REQUEST, ) - probide_wait_stars_to_start_stars_purshase = provide( - WaitStarsToStartStarsPurshase, + probide_wait_stars_to_start_stars_purchase = provide( + WaitStarsToStartStarsPurchase, scope=Scope.REQUEST, ) provide_start_stars_purchase = provide( @@ -275,12 +275,12 @@ class ApplicationWithoutAiogramRequestDataProvider(Provider): provide_view_user = provide(ViewUser, scope=Scope.REQUEST) provide_register_user = provide(RegisterUser, scope=Scope.REQUEST) provide_remove_emoji = provide(RemoveEmoji, scope=Scope.REQUEST) - probide_complete_stars_purshase_payment = provide( - CompleteStarsPurshasePayment, + probide_complete_stars_purchase_payment = provide( + CompleteStarsPurchasePayment, scope=Scope.REQUEST, ) - probide_start_stars_purshase_payment_completion = provide( - StartStarsPurshasePaymentCompletion, + probide_start_stars_purchase_payment_completion = provide( + StartStarsPurchasePaymentCompletion, scope=Scope.REQUEST, ) diff --git a/src/ttt/main/aiogram_slim/__init__.py b/src/ttt/main/aiogram_prod/__init__.py similarity index 100% rename from src/ttt/main/aiogram_slim/__init__.py rename to src/ttt/main/aiogram_prod/__init__.py diff --git a/src/ttt/main/aiogram_slim/__main__.py b/src/ttt/main/aiogram_prod/__main__.py similarity index 100% rename from src/ttt/main/aiogram_slim/__main__.py rename to src/ttt/main/aiogram_prod/__main__.py diff --git a/src/ttt/main/common/di.py b/src/ttt/main/common/di.py index ac6833a..38c4bce 100644 --- a/src/ttt/main/common/di.py +++ b/src/ttt/main/common/di.py @@ -18,8 +18,10 @@ from ttt.application.common.ports.transaction import Transaction from ttt.application.common.ports.uuids import UUIDs from ttt.application.game.common.ports.game_ai_gateway import GameAiGateway +from ttt.application.game.common.ports.game_starting_queue import ( + GameStartingQueue, +) 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.paid_stars_purchase_payment_inbox import ( # noqa: E501 PaidStarsPurchasePaymentInbox, @@ -38,6 +40,9 @@ from ttt.infrastructure.adapters.clock import NotMonotonicUtcClock from ttt.infrastructure.adapters.game_ai_gateway import GeminiGameAiGateway from ttt.infrastructure.adapters.game_log import StructlogGameLog +from ttt.infrastructure.adapters.game_starting_queue import ( + InRedisFixedBatchesWaitingLocations, +) from ttt.infrastructure.adapters.games import InPostgresGames from ttt.infrastructure.adapters.map import MapToPostgres from ttt.infrastructure.adapters.paid_stars_purchase_payment_inbox import ( @@ -53,9 +58,6 @@ ) from ttt.infrastructure.adapters.users import InPostgresUsers from ttt.infrastructure.adapters.uuids import UUIDv4s -from ttt.infrastructure.adapters.waiting_locations import ( - InRedisFixedBatchesWaitingLocations, -) from ttt.infrastructure.background_tasks import BackgroundTasks from ttt.infrastructure.nats.paid_stars_purchase_payment_inbox import ( InNatsPaidStarsPurchasePaymentInbox as OriginalInNatsPaidStarsPurchasePaymentInbox, # noqa: E501 @@ -216,15 +218,15 @@ def provide_randoms(self) -> Randoms: return MersenneTwisterRandoms() @provide(scope=Scope.REQUEST) - def provide_waiting_locations( + def provide_game_starting_queue( self, redis: Redis, envs: Envs, - ) -> WaitingLocations: + ) -> GameStartingQueue: return InRedisFixedBatchesWaitingLocations( InRedisFixedBatches( redis, - "waiting_locations", + "game_starting_queue", envs.game_waiting_queue_pulling_timeout_min_ms, envs.game_waiting_queue_pulling_timeout_salt_ms, ), diff --git a/src/ttt/presentation/adapters/stars_purchase_payment_gateway.py b/src/ttt/presentation/adapters/stars_purchase_payment_gateway.py index 2787318..26b48a7 100644 --- a/src/ttt/presentation/adapters/stars_purchase_payment_gateway.py +++ b/src/ttt/presentation/adapters/stars_purchase_payment_gateway.py @@ -27,10 +27,10 @@ class AiogramInAndBufferOutStarsPurchasePaymentGateway( async def send_invoice( self, - purshase: StarsPurchase, + purchase: StarsPurchase, location: UserLocation, ) -> None: - await stars_invoce(self._bot, location, purshase, self._payments_token) + await stars_invoce(self._bot, location, purchase, self._payments_token) async def start_payment(self, payment_id: UUID) -> None: await not_none(self._pre_checkout_query).answer(ok=True) diff --git a/src/ttt/presentation/adapters/user_views.py b/src/ttt/presentation/adapters/user_views.py index f457504..07f947c 100644 --- a/src/ttt/presentation/adapters/user_views.py +++ b/src/ttt/presentation/adapters/user_views.py @@ -35,7 +35,7 @@ stars_added_message, stars_will_be_added_message, wait_emoji_message, - wait_stars_to_start_stars_purshase_message, + wait_stars_to_start_stars_purchase_message, ) @@ -123,12 +123,12 @@ async def selected_emoji_removed_view( class AiogramMessagesAsStarsPurchaseUserViews(StarsPurchaseUserViews): _bot: Bot - async def wait_stars_to_start_stars_purshase_view( + async def wait_stars_to_start_stars_purchase_view( self, location: UserLocation, /, ) -> None: - await wait_stars_to_start_stars_purshase_message( + await wait_stars_to_start_stars_purchase_message( self._bot, location.chat_id, ) @@ -147,10 +147,10 @@ async def stars_purchase_will_be_completed_view( ) -> None: await stars_will_be_added_message(self._bot, location.chat_id) - async def completed_stars_purshase_view( + async def completed_stars_purchase_view( self, user: User, - purshase_id: UUID, + purchase_id: UUID, location: UserLocation, /, ) -> None: diff --git a/src/ttt/presentation/aiogram/user/invoices.py b/src/ttt/presentation/aiogram/user/invoices.py index 6b94b9f..33afa70 100644 --- a/src/ttt/presentation/aiogram/user/invoices.py +++ b/src/ttt/presentation/aiogram/user/invoices.py @@ -11,51 +11,51 @@ from ttt.entities.core.user.stars_purchase import StarsPurchase -class StarsPurshaseInvoicePayload(BaseModel): +class StarsPurchaseInvoicePayload(BaseModel): type_: Literal["s"] = "s" - purshase_id: UUID = Field(alias="s") + purchase_id: UUID = Field(alias="s") location_user_id: int = Field(alias="p") location_chat_id: int = Field(alias="c") @classmethod def of( cls, - purshase_id: UUID, + purchase_id: UUID, location: UserLocation, - ) -> "StarsPurshaseInvoicePayload": - return StarsPurshaseInvoicePayload( - s=purshase_id, + ) -> "StarsPurchaseInvoicePayload": + return StarsPurchaseInvoicePayload( + s=purchase_id, p=location.user_id, c=location.chat_id, ) -type InvocePayload = StarsPurshaseInvoicePayload +type InvocePayload = StarsPurchaseInvoicePayload invoce_payload_adapter = TypeAdapter[InvocePayload](InvocePayload) async def stars_invoce( bot: Bot, location: UserLocation, - purshase: StarsPurchase, + purchase: StarsPurchase, payments_token: str, ) -> None: price = LabeledPrice( - label=f"{purshase.stars} звёзд", - amount=price_of_stars(purshase.stars).total_kopecks(), + label=f"{purchase.stars} звёзд", + amount=price_of_stars(purchase.stars).total_kopecks(), ) - payload_model = StarsPurshaseInvoicePayload.of(purshase.id_, location) + payload_model = StarsPurchaseInvoicePayload.of(purchase.id_, location) payload = payload_model.model_dump_json(by_alias=True) provider_data = json.dumps({ "receipt": { "items": [ { - "description": f"{purshase.stars} звёзд", + "description": f"{purchase.stars} звёзд", "quantity": 1, "amount": { - "value": float(price_of_stars(purshase.stars)), + "value": float(price_of_stars(purchase.stars)), "currency": "RUB", }, "vat_code": 1, diff --git a/src/ttt/presentation/aiogram/user/messages.py b/src/ttt/presentation/aiogram/user/messages.py index 85b399d..9f36147 100644 --- a/src/ttt/presentation/aiogram/user/messages.py +++ b/src/ttt/presentation/aiogram/user/messages.py @@ -100,7 +100,7 @@ async def selected_emoji_removed_message(bot: Bot, chat_id: int) -> None: await bot.send_message(chat_id, "🎭 Эмоджи убран") -async def wait_stars_to_start_stars_purshase_message( +async def wait_stars_to_start_stars_purchase_message( bot: Bot, chat_id: int, ) -> None: diff --git a/src/ttt/presentation/aiogram/user/routes/all.py b/src/ttt/presentation/aiogram/user/routes/all.py index de3bbe1..9696533 100644 --- a/src/ttt/presentation/aiogram/user/routes/all.py +++ b/src/ttt/presentation/aiogram/user/routes/all.py @@ -25,8 +25,8 @@ from ttt.presentation.aiogram.user.routes.stars_purchase.start_stars_purchase import ( # noqa: E501 start_stars_purchase_router, ) -from ttt.presentation.aiogram.user.routes.stars_purchase.wait_stars_to_start_stars_purshase import ( # noqa: E501 - wait_stars_to_start_stars_purshase_router, +from ttt.presentation.aiogram.user.routes.stars_purchase.wait_stars_to_start_stars_purchase import ( # noqa: E501 + wait_stars_to_start_stars_purchase_router, ) from ttt.presentation.aiogram.user.routes.view_user import ( view_user_router, @@ -44,5 +44,5 @@ start_stars_purchase_router, handle_payment_router, handle_pre_checkout_query_router, - wait_stars_to_start_stars_purshase_router, + wait_stars_to_start_stars_purchase_router, ) diff --git a/src/ttt/presentation/aiogram/user/routes/handle_payment.py b/src/ttt/presentation/aiogram/user/routes/handle_payment.py index bc39d50..c2da6ba 100644 --- a/src/ttt/presentation/aiogram/user/routes/handle_payment.py +++ b/src/ttt/presentation/aiogram/user/routes/handle_payment.py @@ -9,7 +9,7 @@ from ttt.entities.tools.assertion import not_none from ttt.infrastructure.buffer import Buffer from ttt.presentation.aiogram.user.invoices import ( - StarsPurshaseInvoicePayload, + StarsPurchaseInvoicePayload, invoce_payload_adapter, ) @@ -35,13 +35,13 @@ async def _( parent_container = not_none(dishka_container.parent_container) match invoce_payload: - case StarsPurshaseInvoicePayload(): + case StarsPurchaseInvoicePayload(): buffer = await parent_container.get( Buffer[PaidStarsPurchasePayment], ) buffer.add( PaidStarsPurchasePayment( - invoce_payload.purshase_id, + invoce_payload.purchase_id, UserLocation( invoce_payload.location_user_id, invoce_payload.location_chat_id, diff --git a/src/ttt/presentation/aiogram/user/routes/handle_pre_checkout_query.py b/src/ttt/presentation/aiogram/user/routes/handle_pre_checkout_query.py index 4e0505a..2218574 100644 --- a/src/ttt/presentation/aiogram/user/routes/handle_pre_checkout_query.py +++ b/src/ttt/presentation/aiogram/user/routes/handle_pre_checkout_query.py @@ -6,7 +6,7 @@ StartStarsPurchasePayment, ) from ttt.presentation.aiogram.user.invoices import ( - StarsPurshaseInvoicePayload, + StarsPurchaseInvoicePayload, invoce_payload_adapter, ) @@ -24,9 +24,9 @@ async def _( ) match invoce_payload: - case StarsPurshaseInvoicePayload(): + case StarsPurchaseInvoicePayload(): action = await dishka_container.get(StartStarsPurchasePayment) await action( invoce_payload.location_user_id, - invoce_payload.purshase_id, + invoce_payload.purchase_id, ) diff --git a/src/ttt/presentation/aiogram/user/routes/stars_purchase/wait_stars_to_start_stars_purshase.py b/src/ttt/presentation/aiogram/user/routes/stars_purchase/wait_stars_to_start_stars_purchase.py similarity index 70% rename from src/ttt/presentation/aiogram/user/routes/stars_purchase/wait_stars_to_start_stars_purshase.py rename to src/ttt/presentation/aiogram/user/routes/stars_purchase/wait_stars_to_start_stars_purchase.py index 4adec84..c1ac142 100644 --- a/src/ttt/presentation/aiogram/user/routes/stars_purchase/wait_stars_to_start_stars_purshase.py +++ b/src/ttt/presentation/aiogram/user/routes/stars_purchase/wait_stars_to_start_stars_purchase.py @@ -4,26 +4,26 @@ from aiogram.types import Message from dishka.integrations.aiogram import FromDishka, inject -from ttt.application.user.stars_purchase.wait_stars_to_start_stars_purshase import ( # noqa: E501 - WaitStarsToStartStarsPurshase, +from ttt.application.user.stars_purchase.wait_stars_to_start_stars_purchase import ( # noqa: E501 + WaitStarsToStartStarsPurchase, ) from ttt.entities.core.user.location import UserLocation from ttt.entities.tools.assertion import not_none from ttt.presentation.aiogram.common.messages import anons_are_rohibited_message -wait_stars_to_start_stars_purshase_router = Router(name=__name__) +wait_stars_to_start_stars_purchase_router = Router(name=__name__) -@wait_stars_to_start_stars_purshase_router.message( +@wait_stars_to_start_stars_purchase_router.message( any_state, Command("buy_stars"), ) @inject async def _( message: Message, - wait_stars_to_start_stars_purshase: FromDishka[ - WaitStarsToStartStarsPurshase + wait_stars_to_start_stars_purchase: FromDishka[ + WaitStarsToStartStarsPurchase ], ) -> None: if message.from_user is None: @@ -34,4 +34,4 @@ async def _( return location = UserLocation(message.from_user.id, message.chat.id) - await wait_stars_to_start_stars_purshase(location) + await wait_stars_to_start_stars_purchase(location) diff --git a/tests/test_ttt/test_entities/test_core/test_game.py b/tests/test_ttt/test_entities/test_core/test_game.py index bda8e35..c2d05d0 100644 --- a/tests/test_ttt/test_entities/test_core/test_game.py +++ b/tests/test_ttt/test_entities/test_core/test_game.py @@ -284,7 +284,7 @@ def test_make_move_with_completed_game( # noqa: PLR0913, PLR0917 ) with raises(AlreadyCompletedGameError): - game.make_move(1, 1, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 1, UUID(int=8), middle_random, tracking) def test_make_move_with_not_user( @@ -293,7 +293,7 @@ def test_make_move_with_not_user( tracking: Tracking, ) -> None: with raises(NotPlayerError): - game.make_move(100, 9, UUID(int=8), middle_random, tracking) + game.make_user_move(100, 9, UUID(int=8), middle_random, tracking) def test_make_move_with_not_current_user( @@ -302,7 +302,7 @@ def test_make_move_with_not_current_user( tracking: Tracking, ) -> None: with raises(NotCurrentPlayerError): - game.make_move(2, 9, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 9, UUID(int=8), middle_random, tracking) def test_make_move_with_no_cell( @@ -311,7 +311,7 @@ def test_make_move_with_no_cell( tracking: Tracking, ) -> None: with raises(NoCellError): - game.make_move(1, 10, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 10, UUID(int=8), middle_random, tracking) def test_make_move_with_already_filled_cell( @@ -319,10 +319,10 @@ def test_make_move_with_already_filled_cell( middle_random: Random, tracking: Tracking, ) -> None: - game.make_move(1, 1, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 1, UUID(int=8), middle_random, tracking) with raises(AlreadyFilledCellError): - game.make_move(2, 1, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 1, UUID(int=8), middle_random, tracking) def test_make_move_with_double_move( @@ -330,10 +330,10 @@ def test_make_move_with_double_move( middle_random: Random, tracking: Tracking, ) -> None: - game.make_move(1, 1, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 1, UUID(int=8), middle_random, tracking) with raises(NotCurrentPlayerError): - game.make_move(1, 2, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 2, UUID(int=8), middle_random, tracking) @mark.parametrize("object_", ["result", "user1", "user2", "extra_move"]) @@ -351,13 +351,13 @@ def test_winning_game( # noqa: PLR0913, PLR0917 ___ """ - game.make_move(1, 1, UUID(int=8), middle_random, tracking) - game.make_move(2, 4, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 1, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 4, UUID(int=8), middle_random, tracking) - game.make_move(1, 2, UUID(int=8), middle_random, tracking) - game.make_move(2, 5, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 2, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 5, UUID(int=8), middle_random, tracking) - game.make_move(1, 3, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 3, UUID(int=8), middle_random, tracking) result = game.result if object_ == "result": @@ -395,7 +395,7 @@ def test_winning_game( # noqa: PLR0913, PLR0917 if object_ == "extra_move": with raises(AlreadyCompletedGameError): - game.make_move(2, 6, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 6, UUID(int=8), middle_random, tracking) @mark.parametrize("object_", ["result", "user1", "user2", "extra_move"]) @@ -413,19 +413,19 @@ def test_drawn_game( # noqa: PLR0913, PLR0917 OXO """ - game.make_move(1, 1, UUID(int=8), middle_random, tracking) - game.make_move(2, 2, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 1, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 2, UUID(int=8), middle_random, tracking) - game.make_move(1, 3, UUID(int=8), middle_random, tracking) - game.make_move(2, 5, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 3, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 5, UUID(int=8), middle_random, tracking) - game.make_move(1, 4, UUID(int=8), middle_random, tracking) - game.make_move(2, 7, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 4, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 7, UUID(int=8), middle_random, tracking) - game.make_move(1, 6, UUID(int=8), middle_random, tracking) - game.make_move(2, 9, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 6, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 9, UUID(int=8), middle_random, tracking) - game.make_move(1, 8, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 8, UUID(int=8), middle_random, tracking) result = game.result if object_ == "result": @@ -463,7 +463,7 @@ def test_drawn_game( # noqa: PLR0913, PLR0917 if object_ == "extra_move": with raises(AlreadyCompletedGameError): - game.make_move(2, 5, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 5, UUID(int=8), middle_random, tracking) @mark.parametrize("object_", ["result", "user1", "user2", "extra_move"]) @@ -481,19 +481,19 @@ def test_winning_game_with_filled_board( # noqa: PLR0913, PLR0917 XXO """ - game.make_move(1, 1, UUID(int=8), middle_random, tracking) - game.make_move(2, 2, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 1, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 2, UUID(int=8), middle_random, tracking) - game.make_move(1, 3, UUID(int=8), middle_random, tracking) - game.make_move(2, 4, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 3, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 4, UUID(int=8), middle_random, tracking) - game.make_move(1, 5, UUID(int=8), middle_random, tracking) - game.make_move(2, 6, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 5, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 6, UUID(int=8), middle_random, tracking) - game.make_move(1, 8, UUID(int=8), middle_random, tracking) - game.make_move(2, 9, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 8, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 9, UUID(int=8), middle_random, tracking) - game.make_move(1, 7, UUID(int=8), middle_random, tracking) + game.make_user_move(1, 7, UUID(int=8), middle_random, tracking) result = game.result if object_ == "result": @@ -531,4 +531,4 @@ def test_winning_game_with_filled_board( # noqa: PLR0913, PLR0917 if object_ == "extra_move": with raises(AlreadyCompletedGameError): - game.make_move(2, 5, UUID(int=8), middle_random, tracking) + game.make_user_move(2, 5, UUID(int=8), middle_random, tracking)