33from api .models import ListingIndexModel , ListingReadModel , ListingWriteModel
44from api .shared import dependency
55from config .container import Container , inject
6- from modules .catalog import CatalogModule
76from modules .catalog .application .command import (
87 CreateListingDraftCommand ,
98 DeleteListingDraftCommand ,
109)
1110from modules .catalog .application .query .get_all_listings import GetAllListings
1211from modules .catalog .application .query .get_listing_details import GetListingDetails
12+ from seedwork .application import Application
1313from seedwork .domain .value_objects import Money
1414from seedwork .infrastructure .request_context import request_context
1515
1919@router .get ("/catalog" , tags = ["catalog" ], response_model = ListingIndexModel )
2020@inject
2121async def get_all_listings (
22- module : CatalogModule = dependency (Container .catalog_module ),
22+ app : Application = dependency (Container .application ),
2323):
2424 """
2525 Shows all published listings in the catalog
2626 """
2727 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 )
3130
3231
3332@router .get ("/catalog/{listing_id}" , tags = ["catalog" ], response_model = ListingReadModel )
3433@inject
3534async def get_listing_details (
3635 listing_id ,
37- module : CatalogModule = dependency (Container .catalog_module ),
36+ app : Application = dependency (Container .application ),
3837):
3938 """
4039 Shows listing details
4140 """
4241 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 )
4644
4745
4846@router .post (
@@ -51,7 +49,7 @@ async def get_listing_details(
5149@inject
5250async def create_listing (
5351 request_body : ListingWriteModel ,
54- module : CatalogModule = dependency (Container .catalog_module ),
52+ app : Application = dependency (Container .application ),
5553):
5654 """
5755 Creates a new listing.
@@ -62,12 +60,11 @@ async def create_listing(
6260 ask_price = Money (request_body .ask_price_amount , request_body .ask_price_currency ),
6361 seller_id = request_context .current_user .id ,
6462 )
65- with module .unit_of_work ():
66- command_result = module .execute_command (command )
63+ command_result = app .execute_command (command )
6764
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 )
7168
7269
7370@router .delete (
@@ -76,13 +73,12 @@ async def create_listing(
7673@inject
7774async def delete_listing (
7875 listing_id ,
79- module : CatalogModule = dependency (Container .catalog_module ),
76+ app : Application = dependency (Container .application ),
8077):
8178 """
8279 Delete listing
8380 """
8481 command = DeleteListingDraftCommand (
8582 listing_id = listing_id ,
8683 )
87- with module .unit_of_work ():
88- module .execute_command (command )
84+ app .execute_command (command )
0 commit comments