feat: add currency to product

This commit is contained in:
Vlad Stan 2023-03-03 11:30:48 +02:00
parent dccd781553
commit 39f79fbda5
3 changed files with 16 additions and 1 deletions

View file

@ -137,6 +137,7 @@ class Stall(PartialStall, Nostrable):
class ProductConfig(BaseModel): class ProductConfig(BaseModel):
event_id: Optional[str] event_id: Optional[str]
description: Optional[str] description: Optional[str]
currency: Optional[str]
class PartialProduct(BaseModel): class PartialProduct(BaseModel):
@ -177,6 +178,7 @@ class Product(PartialProduct, Nostrable):
"name": self.name, "name": self.name,
"description": self.config.description, "description": self.config.description,
"image": self.image, "image": self.image,
"currency": self.config.currency,
"price": self.price, "price": self.price,
"quantity": self.quantity, "quantity": self.quantity,
} }

View file

@ -10,7 +10,7 @@ from .event import NostrEvent
async def publish_nostr_event(e: NostrEvent): async def publish_nostr_event(e: NostrEvent):
url = url_for("/nostrclient/api/v1/publish", external=True) url = url_for("/nostrclient/api/v1/publish", external=True)
data = dict(e) data = dict(e)
print("### published", dict(data)) # print("### published", dict(data))
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
try: try:
await client.post( await client.post(

View file

@ -313,6 +313,11 @@ async def api_create_product(
) -> Product: ) -> Product:
try: try:
data.validate_product() 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) product = await create_product(wallet.wallet.user, data=data)
event = await sign_and_send_to_nostr(wallet.wallet.user, product) 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), wallet: WalletTypeInfo = Depends(require_admin_key),
) -> Product: ) -> Product:
try: try:
if product_id != product.id:
raise ValueError("Bad product ID")
product.validate_product() 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) product = await update_product(wallet.wallet.user, product)
event = await sign_and_send_to_nostr(wallet.wallet.user, product) event = await sign_and_send_to_nostr(wallet.wallet.user, product)