1+ import uuid
12from typing import Annotated
23from uuid import UUID
34
45from fastapi import APIRouter , Depends
56
6- from api .dependencies import Application , get_application
7+ from api .dependencies import Application , User , get_application , get_authenticated_user
78from api .models .catalog import ListingIndexModel , ListingReadModel , ListingWriteModel
89from config .container import inject
910from modules .catalog .application .command import (
1314)
1415from modules .catalog .application .query .get_all_listings import GetAllListings
1516from modules .catalog .application .query .get_listing_details import GetListingDetails
16- from seedwork .application import Application
1717from seedwork .domain .value_objects import Money
1818
1919"""
@@ -54,19 +54,21 @@ async def get_listing_details(
5454async def create_listing (
5555 request_body : ListingWriteModel ,
5656 app : Annotated [Application , Depends (get_application )],
57+ current_user : Annotated [User , Depends (get_authenticated_user )],
5758):
5859 """
5960 Creates a new listing.
6061 """
6162 command = CreateListingDraftCommand (
63+ listing_id = uuid .uuid4 (),
6264 title = request_body .title ,
6365 description = request_body .description ,
6466 ask_price = Money (request_body .ask_price_amount , request_body .ask_price_currency ),
65- seller_id = request_context . current_user .id ,
67+ seller_id = current_user .id ,
6668 )
67- command_result = app .execute_command (command )
69+ app .execute_command (command )
6870
69- query = GetListingDetails (listing_id = command_result . payload )
71+ query = GetListingDetails (listing_id = command . listing_id )
7072 query_result = app .execute_query (query )
7173 return dict (query_result .payload )
7274
@@ -76,13 +78,16 @@ async def create_listing(
7678)
7779@inject
7880async def delete_listing (
79- listing_id , app : Annotated [Application , Depends (get_application )]
81+ listing_id ,
82+ app : Annotated [Application , Depends (get_application )],
83+ current_user : Annotated [User , Depends (get_authenticated_user )],
8084):
8185 """
8286 Delete listing
8387 """
8488 command = DeleteListingDraftCommand (
8589 listing_id = listing_id ,
90+ seller_id = current_user .id ,
8691 )
8792 app .execute_command (command )
8893
0 commit comments