From 92c083399145971d30d4a9adf80a41ef47b3125d Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 14 Mar 2023 16:26:04 +0200 Subject: [PATCH] feat: delete merchant from the local DB --- crud.py | 37 +++++++++++++++++++++++++++++++- nostr/nostr_client.py | 2 +- templates/nostrmarket/index.html | 1 + views_api.py | 16 ++++++++++++-- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/crud.py b/crud.py index 747156c..f3b7fa6 100644 --- a/crud.py +++ b/crud.py @@ -73,6 +73,13 @@ async def get_merchant_for_user(user_id: str) -> Optional[Merchant]: return Merchant.from_row(row) if row else None +async def delete_merchants(merchant_id: str) -> None: + await db.execute( + "DELETE FROM nostrmarket.merchants WHERE id = ?", + (merchant_id,), + ) + + ######################################## ZONES ######################################## @@ -220,6 +227,13 @@ async def delete_stall(merchant_id: str, stall_id: str) -> None: ) +async def delete_merchant_stalls(merchant_id: str) -> None: + await db.execute( + "DELETE FROM nostrmarket.stalls WHERE merchant_id = ?", + (merchant_id,), + ) + + ######################################## PRODUCTS ######################################## @@ -326,6 +340,13 @@ async def delete_product(merchant_id: str, product_id: str) -> None: ) +async def delete_merchant_products(merchant_id: str) -> None: + await db.execute( + "DELETE FROM nostrmarket.products WHERE merchant_id = ?", + (merchant_id,), + ) + + ######################################## ORDERS ######################################## @@ -451,6 +472,13 @@ async def update_order_shipped_status( return Order.from_row(row) if row else None +async def delete_merchant_orders(merchant_id: str) -> None: + await db.execute( + "DELETE FROM nostrmarket.orders WHERE merchant_id = ?", + (merchant_id,), + ) + + ######################################## MESSAGES ########################################L @@ -520,6 +548,13 @@ async def get_last_direct_messages_time(public_key: str) -> int: SELECT event_created_at FROM nostrmarket.direct_messages WHERE public_key = ? ORDER BY event_created_at DESC LIMIT 1 """, - (public_key), + (public_key,), ) return row[0] if row else 0 + + +async def delete_merchant_direct_messages(merchant_id: str) -> None: + await db.execute( + "DELETE FROM nostrmarket.direct_messages WHERE merchant_id = ?", + (merchant_id,), + ) diff --git a/nostr/nostr_client.py b/nostr/nostr_client.py index ec0af68..d5bfd7a 100644 --- a/nostr/nostr_client.py +++ b/nostr/nostr_client.py @@ -11,7 +11,7 @@ from .event import NostrEvent async def publish_nostr_event(e: NostrEvent): - print('### publish_nostr_event', e.dict()) + print("### publish_nostr_event", e.dict()) await send_req_queue.put(["EVENT", e.dict()]) diff --git a/templates/nostrmarket/index.html b/templates/nostrmarket/index.html index ecfad1b..32d0ca0 100644 --- a/templates/nostrmarket/index.html +++ b/templates/nostrmarket/index.html @@ -8,6 +8,7 @@