From da41ed365114656b4b4b5be14ab9445a216a98c1 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Mon, 6 Mar 2023 18:07:52 +0200 Subject: [PATCH] feat: add address for order --- crud.py | 5 +++-- migrations.py | 3 ++- models.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crud.py b/crud.py index 6e362b4..c74512f 100644 --- a/crud.py +++ b/crud.py @@ -318,14 +318,15 @@ async def delete_product(user_id: str, product_id: str) -> None: async def create_order(user_id: str, o: Order) -> Order: await db.execute( f""" - INSERT INTO nostrmarket.orders (user_id, id, event_id, pubkey, contact_data, order_items, invoice_id, total) - VALUES (?, ?, ?, ?, ?, ?, ?, ?) + INSERT INTO nostrmarket.orders (user_id, id, event_id, pubkey, address, contact_data, order_items, invoice_id, total) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( user_id, o.id, o.event_id, o.pubkey, + o.address, json.dumps(o.contact.dict() if o.contact else {}), json.dumps([i.dict() for i in o.items]), o.invoice_id, diff --git a/migrations.py b/migrations.py index eead2a7..4ed088b 100644 --- a/migrations.py +++ b/migrations.py @@ -78,9 +78,10 @@ async def m001_initial(db): user_id TEXT NOT NULL, id TEXT PRIMARY KEY, event_id TEXT, - pubkey TEXT, + pubkey EXT NOT NULL, contact_data TEXT NOT NULL DEFAULT '{empty_object}', order_items TEXT NOT NULL, + address TEXT, total REAL NOT NULL, invoice_id TEXT NOT NULL, paid BOOLEAN NOT NULL DEFAULT false, diff --git a/models.py b/models.py index 711a3f4..0cfee8f 100644 --- a/models.py +++ b/models.py @@ -256,7 +256,6 @@ class OrderContact(BaseModel): nostr: Optional[str] phone: Optional[str] email: Optional[str] - address: Optional[str] class PartialOrder(BaseModel): @@ -265,6 +264,7 @@ class PartialOrder(BaseModel): pubkey: str items: List[OrderItem] contact: Optional[OrderContact] + address: Optional[str] def validate_order(self): assert len(self.items) != 0, f"Order has no items. Order: '{self.id}'"