Skip to content

Commit 88e80c3

Browse files
committed
ref(ports): split user_views (#22)
1 parent 67f854f commit 88e80c3

File tree

21 files changed

+288
-181
lines changed

21 files changed

+288
-181
lines changed

src/ttt/application/game/game/start_game.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ttt.application.game.common.ports.games import Games
1010
from ttt.application.game.common.ports.waiting_locations import WaitingLocations
1111
from ttt.application.game.game.ports.game_log import GameLog
12-
from ttt.application.user.common.ports.user_views import UserViews
12+
from ttt.application.user.common.ports.user_views import CommonUserViews
1313
from ttt.application.user.common.ports.users import Users
1414
from ttt.entities.core.game.game import UsersAlreadyInGameError, start_game
1515
from ttt.entities.core.user.location import UserLocation
@@ -22,7 +22,7 @@ class StartGame:
2222
uuids: UUIDs
2323
emojis: Emojis
2424
users: Users
25-
user_views: UserViews
25+
user_views: CommonUserViews
2626
games: Games
2727
game_views: GameViews
2828
waiting_locations: WaitingLocations

src/ttt/application/game/game/wait_game.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ttt.application.game.common.ports.game_views import GameViews
55
from ttt.application.game.common.ports.waiting_locations import WaitingLocations
66
from ttt.application.game.game.ports.game_log import GameLog
7-
from ttt.application.user.common.ports.user_views import UserViews
7+
from ttt.application.user.common.ports.user_views import CommonUserViews
88
from ttt.application.user.common.ports.users import Users
99
from ttt.entities.core.user.location import UserLocation
1010

@@ -13,7 +13,7 @@
1313
class WaitGame:
1414
users: Users
1515
waiting_locations: WaitingLocations
16-
user_views: UserViews
16+
user_views: CommonUserViews
1717
game_views: GameViews
1818
transaction: Transaction
1919
log: GameLog

src/ttt/application/game/game_with_ai/start_game_with_ai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ttt.application.game.common.ports.games import Games
1111
from ttt.application.game.common.ports.waiting_locations import WaitingLocations
1212
from ttt.application.game.game.ports.game_log import GameLog
13-
from ttt.application.user.common.ports.user_views import UserViews
13+
from ttt.application.user.common.ports.user_views import CommonUserViews
1414
from ttt.application.user.common.ports.users import Users
1515
from ttt.entities.core.game.ai import AiType
1616
from ttt.entities.core.game.game import start_game_with_ai
@@ -26,7 +26,7 @@ class StartGameWithAi:
2626
emojis: Emojis
2727
randoms: Randoms
2828
users: Users
29-
user_views: UserViews
29+
user_views: CommonUserViews
3030
games: Games
3131
game_views: GameViews
3232
waiting_locations: WaitingLocations
Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from abc import ABC, abstractmethod
2-
from uuid import UUID
32

4-
from ttt.entities.core.stars import Stars
53
from ttt.entities.core.user.location import UserLocation
6-
from ttt.entities.core.user.user import User
74

85

9-
class UserViews(ABC):
6+
class CommonUserViews(ABC):
107
@abstractmethod
118
async def render_view_of_user_with_id(
129
self,
@@ -35,96 +32,9 @@ async def render_user_registered_view(
3532
/,
3633
) -> None: ...
3734

38-
@abstractmethod
39-
async def render_wait_emoji_to_buy_view(
40-
self,
41-
location: UserLocation,
42-
/,
43-
) -> None: ...
44-
45-
@abstractmethod
46-
async def render_not_enough_stars_to_buy_emoji_view(
47-
self,
48-
location: UserLocation,
49-
stars_to_become_enough: Stars,
50-
/,
51-
) -> None: ...
52-
53-
@abstractmethod
54-
async def render_emoji_already_purchased_view(
55-
self,
56-
location: UserLocation,
57-
/,
58-
) -> None: ...
59-
60-
@abstractmethod
61-
async def render_emoji_was_purchased_view(
62-
self,
63-
location: UserLocation,
64-
/,
65-
) -> None: ...
66-
67-
@abstractmethod
68-
async def render_invalid_emoji_to_buy_view(
69-
self,
70-
location: UserLocation,
71-
/,
72-
) -> None: ...
73-
74-
@abstractmethod
75-
async def render_invalid_emoji_to_select_view(
76-
self,
77-
location: UserLocation,
78-
/,
79-
) -> None: ...
80-
81-
@abstractmethod
82-
async def render_emoji_not_purchased_to_select_view(
83-
self,
84-
location: UserLocation,
85-
/,
86-
) -> None: ...
87-
88-
@abstractmethod
89-
async def render_emoji_selected_view(
90-
self,
91-
location: UserLocation,
92-
/,
93-
) -> None: ...
94-
9535
@abstractmethod
9636
async def render_selected_emoji_removed_view(
9737
self,
9838
location: UserLocation,
9939
/,
10040
) -> None: ...
101-
102-
@abstractmethod
103-
async def render_wait_stars_to_start_stars_purshase_view(
104-
self,
105-
location: UserLocation,
106-
/,
107-
) -> None: ...
108-
109-
@abstractmethod
110-
async def render_invalid_stars_for_stars_purchase_view(
111-
self,
112-
location: UserLocation,
113-
/,
114-
) -> None: ...
115-
116-
@abstractmethod
117-
async def render_stars_purchase_will_be_completed_view(
118-
self,
119-
location: UserLocation,
120-
/,
121-
) -> None: ...
122-
123-
@abstractmethod
124-
async def render_completed_stars_purshase_view(
125-
self,
126-
user: User,
127-
purshase_id: UUID,
128-
location: UserLocation,
129-
/,
130-
) -> None: ...

src/ttt/application/user/emoji_purchase/buy_emoji.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
UserFsm,
1010
WaitingEmojiToBuyState,
1111
)
12-
from ttt.application.user.common.ports.user_views import UserViews
12+
from ttt.application.user.common.ports.user_views import CommonUserViews
1313
from ttt.application.user.common.ports.users import Users
1414
from ttt.application.user.emoji_purchase.ports.user_log import (
1515
EmojiPurchaseUserLog,
1616
)
17+
from ttt.application.user.emoji_purchase.ports.user_views import (
18+
EmojiPurchaseUserViews,
19+
)
1720
from ttt.entities.core.user.location import UserLocation
1821
from ttt.entities.core.user.user import (
1922
EmojiAlreadyPurchasedError,
@@ -30,7 +33,8 @@ class BuyEmoji:
3033
clock: Clock
3134
transaction: Transaction
3235
users: Users
33-
user_views: UserViews
36+
common_views: CommonUserViews
37+
emoji_purchase_views: EmojiPurchaseUserViews
3438
map_: Map
3539
log: EmojiPurchaseUserLog
3640

@@ -42,13 +46,17 @@ async def __call__(
4246
await self.fsm.state(WaitingEmojiToBuyState)
4347

4448
if emoji_str is None:
45-
await self.user_views.render_invalid_emoji_to_buy_view(location)
49+
await self.emoji_purchase_views.render_invalid_emoji_to_buy_view(
50+
location,
51+
)
4652
return
4753

4854
try:
4955
emoji = Emoji(emoji_str)
5056
except InvalidEmojiError:
51-
await self.user_views.render_invalid_emoji_to_buy_view(location)
57+
await self.emoji_purchase_views.render_invalid_emoji_to_buy_view(
58+
location,
59+
)
5260
return
5361

5462
purchased_emoji_id, current_datetime = await gather(
@@ -60,7 +68,7 @@ async def __call__(
6068
user = await self.users.user_with_id(location.user_id)
6169

6270
if user is None:
63-
await self.user_views.render_user_is_not_registered_view(
71+
await self.common_views.render_user_is_not_registered_view(
6472
location,
6573
)
6674
await self.fsm.set(None)
@@ -81,12 +89,12 @@ async def __call__(
8189
emoji,
8290
)
8391
await self.fsm.set(None)
84-
await self.user_views.render_emoji_already_purchased_view(
92+
await self.emoji_purchase_views.render_emoji_already_purchased_view(
8593
location,
8694
)
8795
except NotEnoughStarsError as error:
8896
await self.fsm.set(None)
89-
await self.user_views.render_not_enough_stars_to_buy_emoji_view(
97+
await self.emoji_purchase_views.render_not_enough_stars_to_buy_emoji_view(
9098
location,
9199
error.stars_to_become_enough,
92100
)
@@ -95,6 +103,6 @@ async def __call__(
95103

96104
await self.map_(tracking)
97105
await self.fsm.set(None)
98-
await self.user_views.render_emoji_was_purchased_view(
106+
await self.emoji_purchase_views.render_emoji_was_purchased_view(
99107
location,
100108
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from abc import ABC, abstractmethod
2+
3+
from ttt.entities.core.stars import Stars
4+
from ttt.entities.core.user.location import UserLocation
5+
6+
7+
class EmojiPurchaseUserViews(ABC):
8+
@abstractmethod
9+
async def render_wait_emoji_to_buy_view(
10+
self,
11+
location: UserLocation,
12+
/,
13+
) -> None: ...
14+
15+
@abstractmethod
16+
async def render_not_enough_stars_to_buy_emoji_view(
17+
self,
18+
location: UserLocation,
19+
stars_to_become_enough: Stars,
20+
/,
21+
) -> None: ...
22+
23+
@abstractmethod
24+
async def render_emoji_already_purchased_view(
25+
self,
26+
location: UserLocation,
27+
/,
28+
) -> None: ...
29+
30+
@abstractmethod
31+
async def render_emoji_was_purchased_view(
32+
self,
33+
location: UserLocation,
34+
/,
35+
) -> None: ...
36+
37+
@abstractmethod
38+
async def render_invalid_emoji_to_buy_view(
39+
self,
40+
location: UserLocation,
41+
/,
42+
) -> None: ...

src/ttt/application/user/emoji_purchase/wait_emoji_to_buy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
UserFsm,
66
WaitingEmojiToBuyState,
77
)
8-
from ttt.application.user.common.ports.user_views import UserViews
98
from ttt.application.user.emoji_purchase.ports.user_log import (
109
EmojiPurchaseUserLog,
1110
)
11+
from ttt.application.user.emoji_purchase.ports.user_views import (
12+
EmojiPurchaseUserViews,
13+
)
1214
from ttt.entities.core.user.location import UserLocation
1315

1416

1517
@dataclass(frozen=True, unsafe_hash=False)
1618
class WaitEmojiToBuy:
1719
fsm: UserFsm
18-
user_views: UserViews
20+
user_views: EmojiPurchaseUserViews
1921
log: EmojiPurchaseUserLog
2022

2123
async def __call__(self, location: UserLocation) -> None:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from abc import ABC, abstractmethod
2+
3+
from ttt.entities.core.user.location import UserLocation
4+
5+
6+
class EmojiSelectionUserViews(ABC):
7+
@abstractmethod
8+
async def render_invalid_emoji_to_select_view(
9+
self,
10+
location: UserLocation,
11+
/,
12+
) -> None: ...
13+
14+
@abstractmethod
15+
async def render_emoji_not_purchased_to_select_view(
16+
self,
17+
location: UserLocation,
18+
/,
19+
) -> None: ...
20+
21+
@abstractmethod
22+
async def render_emoji_selected_view(
23+
self,
24+
location: UserLocation,
25+
/,
26+
) -> None: ...
27+
28+
@abstractmethod
29+
async def render_wait_emoji_to_select_view(
30+
self,
31+
location: UserLocation,
32+
/,
33+
) -> None: ...

0 commit comments

Comments
 (0)