3
3
from api .models import ListingIndexModel , ListingReadModel , ListingWriteModel
4
4
from api .shared import dependency
5
5
from config .container import Container , inject
6
- from modules .catalog import CatalogModule
7
6
from modules .catalog .application .command import (
8
7
CreateListingDraftCommand ,
9
8
DeleteListingDraftCommand ,
10
9
)
11
10
from modules .catalog .application .query .get_all_listings import GetAllListings
12
11
from modules .catalog .application .query .get_listing_details import GetListingDetails
12
+ from seedwork .application import Application
13
13
from seedwork .domain .value_objects import Money
14
14
from seedwork .infrastructure .request_context import request_context
15
15
19
19
@router .get ("/catalog" , tags = ["catalog" ], response_model = ListingIndexModel )
20
20
@inject
21
21
async def get_all_listings (
22
- module : CatalogModule = dependency (Container .catalog_module ),
22
+ app : Application = dependency (Container .application ),
23
23
):
24
24
"""
25
25
Shows all published listings in the catalog
26
26
"""
27
27
query = GetAllListings ()
28
- with module .unit_of_work ():
29
- query_result = module .execute_query (query )
30
- return dict (data = query_result .payload )
28
+ query_result = app .execute_query (query )
29
+ return dict (data = query_result .payload )
31
30
32
31
33
32
@router .get ("/catalog/{listing_id}" , tags = ["catalog" ], response_model = ListingReadModel )
34
33
@inject
35
34
async def get_listing_details (
36
35
listing_id ,
37
- module : CatalogModule = dependency (Container .catalog_module ),
36
+ app : Application = dependency (Container .application ),
38
37
):
39
38
"""
40
39
Shows listing details
41
40
"""
42
41
query = GetListingDetails (listing_id = listing_id )
43
- with module .unit_of_work ():
44
- query_result = module .execute_query (query )
45
- return query_result .payload
42
+ query_result = app .execute_query (query )
43
+ return dict (data = query_result .payload )
46
44
47
45
48
46
@router .post (
@@ -51,7 +49,7 @@ async def get_listing_details(
51
49
@inject
52
50
async def create_listing (
53
51
request_body : ListingWriteModel ,
54
- module : CatalogModule = dependency (Container .catalog_module ),
52
+ app : Application = dependency (Container .application ),
55
53
):
56
54
"""
57
55
Creates a new listing.
@@ -62,12 +60,11 @@ async def create_listing(
62
60
ask_price = Money (request_body .ask_price_amount , request_body .ask_price_currency ),
63
61
seller_id = request_context .current_user .id ,
64
62
)
65
- with module .unit_of_work ():
66
- command_result = module .execute_command (command )
63
+ command_result = app .execute_command (command )
67
64
68
- query = GetListingDetails (listing_id = command_result .result )
69
- query_result = module .execute_query (query )
70
- return query_result .payload
65
+ query = GetListingDetails (listing_id = command_result .payload )
66
+ query_result = app .execute_query (query )
67
+ return dict ( data = query_result .payload )
71
68
72
69
73
70
@router .delete (
@@ -76,13 +73,12 @@ async def create_listing(
76
73
@inject
77
74
async def delete_listing (
78
75
listing_id ,
79
- module : CatalogModule = dependency (Container .catalog_module ),
76
+ app : Application = dependency (Container .application ),
80
77
):
81
78
"""
82
79
Delete listing
83
80
"""
84
81
command = DeleteListingDraftCommand (
85
82
listing_id = listing_id ,
86
83
)
87
- with module .unit_of_work ():
88
- module .execute_command (command )
84
+ app .execute_command (command )
0 commit comments