diff --git a/models.py b/models.py index cc82538..194cf04 100644 --- a/models.py +++ b/models.py @@ -137,6 +137,7 @@ class Stall(PartialStall, Nostrable): class ProductConfig(BaseModel): event_id: Optional[str] description: Optional[str] + currency: Optional[str] class PartialProduct(BaseModel): @@ -177,6 +178,7 @@ class Product(PartialProduct, Nostrable): "name": self.name, "description": self.config.description, "image": self.image, + "currency": self.config.currency, "price": self.price, "quantity": self.quantity, } diff --git a/nostr/nostr_client.py b/nostr/nostr_client.py index 29a5b42..306c123 100644 --- a/nostr/nostr_client.py +++ b/nostr/nostr_client.py @@ -10,7 +10,7 @@ from .event import NostrEvent async def publish_nostr_event(e: NostrEvent): url = url_for("/nostrclient/api/v1/publish", external=True) data = dict(e) - print("### published", dict(data)) + # print("### published", dict(data)) async with httpx.AsyncClient() as client: try: await client.post( diff --git a/views_api.py b/views_api.py index e095ee8..4680977 100644 --- a/views_api.py +++ b/views_api.py @@ -313,6 +313,11 @@ async def api_create_product( ) -> Product: try: data.validate_product() + + stall = await get_stall(wallet.wallet.user, data.stall_id) + assert stall, "Stall missing for product" + data.config.currency = stall.currency + product = await create_product(wallet.wallet.user, data=data) event = await sign_and_send_to_nostr(wallet.wallet.user, product) @@ -341,7 +346,15 @@ async def api_update_product( wallet: WalletTypeInfo = Depends(require_admin_key), ) -> Product: try: + if product_id != product.id: + raise ValueError("Bad product ID") + product.validate_product() + + stall = await get_stall(wallet.wallet.user, product.stall_id) + assert stall, "Stall missing for product" + product.config.currency = stall.currency + product = await update_product(wallet.wallet.user, product) event = await sign_and_send_to_nostr(wallet.wallet.user, product)