mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-24 14:51:05 +01:00
Merge remote-tracking branch 'origin/diagon-alley' into diagon-alley
This commit is contained in:
commit
9b69851155
17 changed files with 383 additions and 379 deletions
|
@ -1,7 +1,7 @@
|
|||
<h1>Diagon Alley</h1>
|
||||
<h1>Shop</h1>
|
||||
<h2>A movable market stand</h2>
|
||||
Make a list of products to sell, point the list to an relay (or many), stack sats.
|
||||
Diagon Alley is a movable market stand, for anon transactions. You then give permission for an relay to list those products. Delivery addresses are sent through the Lightning Network.
|
||||
Shop is a movable market stand, for anon transactions. You then give permission for an relay to list those products. Delivery addresses are sent through the Lightning Network.
|
||||
<img src="https://i.imgur.com/P1tvBSG.png">
|
||||
|
||||
<h2>API endpoints</h2>
|
|
@ -7,20 +7,20 @@ from lnbits.db import Database
|
|||
from lnbits.helpers import template_renderer
|
||||
from lnbits.tasks import catch_everything_and_restart
|
||||
|
||||
db = Database("ext_diagonalley")
|
||||
db = Database("ext_shop")
|
||||
|
||||
diagonalley_ext: APIRouter = APIRouter(prefix="/diagonalley", tags=["diagonalley"])
|
||||
shop_ext: APIRouter = APIRouter(prefix="/shop", tags=["shop"])
|
||||
|
||||
diagonalley_static_files = [
|
||||
shop_static_files = [
|
||||
{
|
||||
"path": "/diagonalley/static",
|
||||
"app": StaticFiles(directory="lnbits/extensions/diagonalley/static"),
|
||||
"name": "diagonalley_static",
|
||||
"path": "/shop/static",
|
||||
"app": StaticFiles(directory="lnbits/extensions/shop/static"),
|
||||
"name": "shop_static",
|
||||
}
|
||||
]
|
||||
|
||||
# if 'nostradmin' not in LNBITS_ADMIN_EXTENSIONS:
|
||||
# @diagonalley_ext.get("/", response_class=HTMLResponse)
|
||||
# @shop_ext.get("/", response_class=HTMLResponse)
|
||||
# async def index(request: Request):
|
||||
# return template_renderer().TemplateResponse(
|
||||
# "error.html", {"request": request, "err": "Ask system admin to enable NostrAdmin!"}
|
||||
|
@ -28,9 +28,9 @@ diagonalley_static_files = [
|
|||
# else:
|
||||
|
||||
|
||||
def diagonalley_renderer():
|
||||
return template_renderer(["lnbits/extensions/diagonalley/templates"])
|
||||
# return template_renderer(["lnbits/extensions/diagonalley/templates"])
|
||||
def shop_renderer():
|
||||
return template_renderer(["lnbits/extensions/shop/templates"])
|
||||
# return template_renderer(["lnbits/extensions/shop/templates"])
|
||||
|
||||
|
||||
from .tasks import wait_for_paid_invoices
|
||||
|
@ -38,6 +38,6 @@ from .views import * # noqa
|
|||
from .views_api import * # noqa
|
||||
|
||||
|
||||
def diagonalley_start():
|
||||
def shop_start():
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
|
@ -29,11 +29,11 @@ from .models import (
|
|||
###Products
|
||||
|
||||
|
||||
async def create_diagonalley_product(data: createProduct) -> Products:
|
||||
async def create_shop_product(data: createProduct) -> Products:
|
||||
product_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
f"""
|
||||
INSERT INTO diagonalley.products (id, stall, product, categories, description, image, price, quantity)
|
||||
INSERT INTO shop.products (id, stall, product, categories, description, image, price, quantity)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
|
@ -47,59 +47,59 @@ async def create_diagonalley_product(data: createProduct) -> Products:
|
|||
data.quantity,
|
||||
),
|
||||
)
|
||||
product = await get_diagonalley_product(product_id)
|
||||
product = await get_shop_product(product_id)
|
||||
assert product, "Newly created product couldn't be retrieved"
|
||||
return product
|
||||
|
||||
|
||||
async def update_diagonalley_product(product_id: str, **kwargs) -> Optional[Stalls]:
|
||||
async def update_shop_product(product_id: str, **kwargs) -> Optional[Stalls]:
|
||||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||
|
||||
await db.execute(
|
||||
f"UPDATE diagonalley.products SET {q} WHERE id = ?",
|
||||
f"UPDATE shop.products SET {q} WHERE id = ?",
|
||||
(*kwargs.values(), product_id),
|
||||
)
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.products WHERE id = ?", (product_id,)
|
||||
"SELECT * FROM shop.products WHERE id = ?", (product_id,)
|
||||
)
|
||||
|
||||
return Products(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_product(product_id: str) -> Optional[Products]:
|
||||
async def get_shop_product(product_id: str) -> Optional[Products]:
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.products WHERE id = ?", (product_id,)
|
||||
"SELECT * FROM shop.products WHERE id = ?", (product_id,)
|
||||
)
|
||||
return Products(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_products(stall_ids: Union[str, List[str]]) -> List[Products]:
|
||||
async def get_shop_products(stall_ids: Union[str, List[str]]) -> List[Products]:
|
||||
if isinstance(stall_ids, str):
|
||||
stall_ids = [stall_ids]
|
||||
|
||||
# with open_ext_db("diagonalley") as db:
|
||||
# with open_ext_db("shop") as db:
|
||||
q = ",".join(["?"] * len(stall_ids))
|
||||
rows = await db.fetchall(
|
||||
f"""
|
||||
SELECT * FROM diagonalley.products WHERE stall IN ({q})
|
||||
SELECT * FROM shop.products WHERE stall IN ({q})
|
||||
""",
|
||||
(*stall_ids,),
|
||||
)
|
||||
return [Products(**row) for row in rows]
|
||||
|
||||
|
||||
async def delete_diagonalley_product(product_id: str) -> None:
|
||||
await db.execute("DELETE FROM diagonalley.products WHERE id = ?", (product_id,))
|
||||
async def delete_shop_product(product_id: str) -> None:
|
||||
await db.execute("DELETE FROM shop.products WHERE id = ?", (product_id,))
|
||||
|
||||
|
||||
###zones
|
||||
|
||||
|
||||
async def create_diagonalley_zone(user, data: createZones) -> Zones:
|
||||
async def create_shop_zone(user, data: createZones) -> Zones:
|
||||
zone_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
f"""
|
||||
INSERT INTO diagonalley.zones (
|
||||
INSERT INTO shop.zones (
|
||||
id,
|
||||
"user",
|
||||
cost,
|
||||
|
@ -111,45 +111,45 @@ async def create_diagonalley_zone(user, data: createZones) -> Zones:
|
|||
(zone_id, user, data.cost, data.countries.lower()),
|
||||
)
|
||||
|
||||
zone = await get_diagonalley_zone(zone_id)
|
||||
zone = await get_shop_zone(zone_id)
|
||||
assert zone, "Newly created zone couldn't be retrieved"
|
||||
return zone
|
||||
|
||||
|
||||
async def update_diagonalley_zone(zone_id: str, **kwargs) -> Optional[Zones]:
|
||||
async def update_shop_zone(zone_id: str, **kwargs) -> Optional[Zones]:
|
||||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||
await db.execute(
|
||||
f"UPDATE diagonalley.zones SET {q} WHERE id = ?",
|
||||
f"UPDATE shop.zones SET {q} WHERE id = ?",
|
||||
(*kwargs.values(), zone_id),
|
||||
)
|
||||
row = await db.fetchone("SELECT * FROM diagonalley.zones WHERE id = ?", (zone_id,))
|
||||
row = await db.fetchone("SELECT * FROM shop.zones WHERE id = ?", (zone_id,))
|
||||
return Zones(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_zone(zone_id: str) -> Optional[Zones]:
|
||||
row = await db.fetchone("SELECT * FROM diagonalley.zones WHERE id = ?", (zone_id,))
|
||||
async def get_shop_zone(zone_id: str) -> Optional[Zones]:
|
||||
row = await db.fetchone("SELECT * FROM shop.zones WHERE id = ?", (zone_id,))
|
||||
return Zones(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_zones(user: str) -> List[Zones]:
|
||||
async def get_shop_zones(user: str) -> List[Zones]:
|
||||
rows = await db.fetchall(
|
||||
'SELECT * FROM diagonalley.zones WHERE "user" = ?', (user,)
|
||||
'SELECT * FROM shop.zones WHERE "user" = ?', (user,)
|
||||
)
|
||||
return [Zones(**row) for row in rows]
|
||||
|
||||
|
||||
async def delete_diagonalley_zone(zone_id: str) -> None:
|
||||
await db.execute("DELETE FROM diagonalley.zones WHERE id = ?", (zone_id,))
|
||||
async def delete_shop_zone(zone_id: str) -> None:
|
||||
await db.execute("DELETE FROM shop.zones WHERE id = ?", (zone_id,))
|
||||
|
||||
|
||||
###Stalls
|
||||
|
||||
|
||||
async def create_diagonalley_stall(data: createStalls) -> Stalls:
|
||||
async def create_shop_stall(data: createStalls) -> Stalls:
|
||||
stall_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
f"""
|
||||
INSERT INTO diagonalley.stalls (
|
||||
INSERT INTO shop.stalls (
|
||||
id,
|
||||
wallet,
|
||||
name,
|
||||
|
@ -171,62 +171,62 @@ async def create_diagonalley_stall(data: createStalls) -> Stalls:
|
|||
),
|
||||
)
|
||||
|
||||
stall = await get_diagonalley_stall(stall_id)
|
||||
stall = await get_shop_stall(stall_id)
|
||||
assert stall, "Newly created stall couldn't be retrieved"
|
||||
return stall
|
||||
|
||||
|
||||
async def update_diagonalley_stall(stall_id: str, **kwargs) -> Optional[Stalls]:
|
||||
async def update_shop_stall(stall_id: str, **kwargs) -> Optional[Stalls]:
|
||||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||
await db.execute(
|
||||
f"UPDATE diagonalley.stalls SET {q} WHERE id = ?",
|
||||
f"UPDATE shop.stalls SET {q} WHERE id = ?",
|
||||
(*kwargs.values(), stall_id),
|
||||
)
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.stalls WHERE id = ?", (stall_id,)
|
||||
"SELECT * FROM shop.stalls WHERE id = ?", (stall_id,)
|
||||
)
|
||||
return Stalls(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_stall(stall_id: str) -> Optional[Stalls]:
|
||||
async def get_shop_stall(stall_id: str) -> Optional[Stalls]:
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.stalls WHERE id = ?", (stall_id,)
|
||||
"SELECT * FROM shop.stalls WHERE id = ?", (stall_id,)
|
||||
)
|
||||
return Stalls(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_stalls(wallet_ids: Union[str, List[str]]) -> List[Stalls]:
|
||||
async def get_shop_stalls(wallet_ids: Union[str, List[str]]) -> List[Stalls]:
|
||||
q = ",".join(["?"] * len(wallet_ids))
|
||||
rows = await db.fetchall(
|
||||
f"SELECT * FROM diagonalley.stalls WHERE wallet IN ({q})", (*wallet_ids,)
|
||||
f"SELECT * FROM shop.stalls WHERE wallet IN ({q})", (*wallet_ids,)
|
||||
)
|
||||
return [Stalls(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_diagonalley_stalls_by_ids(
|
||||
async def get_shop_stalls_by_ids(
|
||||
stall_ids: Union[str, List[str]]
|
||||
) -> List[Stalls]:
|
||||
q = ",".join(["?"] * len(stall_ids))
|
||||
rows = await db.fetchall(
|
||||
f"SELECT * FROM diagonalley.stalls WHERE id IN ({q})", (*stall_ids,)
|
||||
f"SELECT * FROM shop.stalls WHERE id IN ({q})", (*stall_ids,)
|
||||
)
|
||||
return [Stalls(**row) for row in rows]
|
||||
|
||||
|
||||
async def delete_diagonalley_stall(stall_id: str) -> None:
|
||||
await db.execute("DELETE FROM diagonalley.stalls WHERE id = ?", (stall_id,))
|
||||
async def delete_shop_stall(stall_id: str) -> None:
|
||||
await db.execute("DELETE FROM shop.stalls WHERE id = ?", (stall_id,))
|
||||
|
||||
|
||||
###Orders
|
||||
|
||||
|
||||
async def create_diagonalley_order(data: createOrder, invoiceid: str) -> Orders:
|
||||
async def create_shop_order(data: createOrder, invoiceid: str) -> Orders:
|
||||
returning = "" if db.type == SQLITE else "RETURNING ID"
|
||||
method = db.execute if db.type == SQLITE else db.fetchone
|
||||
|
||||
result = await (method)(
|
||||
f"""
|
||||
INSERT INTO diagonalley.orders (wallet, shippingzone, address, email, total, invoiceid, paid, shipped)
|
||||
INSERT INTO shop.orders (wallet, shippingzone, address, email, total, invoiceid, paid, shipped)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
{returning}
|
||||
""",
|
||||
|
@ -245,19 +245,19 @@ async def create_diagonalley_order(data: createOrder, invoiceid: str) -> Orders:
|
|||
return result._result_proxy.lastrowid
|
||||
else:
|
||||
return result[0]
|
||||
# link = await get_diagonalley_order(link.id)
|
||||
# link = await get_shop_order(link.id)
|
||||
# assert link, "Newly created link couldn't be retrieved"
|
||||
# return link
|
||||
|
||||
|
||||
async def create_diagonalley_order_details(
|
||||
async def create_shop_order_details(
|
||||
order_id: str, data: List[createOrderDetails]
|
||||
):
|
||||
for item in data:
|
||||
item_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO diagonalley.order_details (id, order_id, product_id, quantity)
|
||||
INSERT INTO shop.order_details (id, order_id, product_id, quantity)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
|
@ -267,36 +267,36 @@ async def create_diagonalley_order_details(
|
|||
item.quantity,
|
||||
),
|
||||
)
|
||||
order_details = await get_diagonalley_order_details(order_id)
|
||||
order_details = await get_shop_order_details(order_id)
|
||||
return order_details
|
||||
|
||||
|
||||
async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]:
|
||||
async def get_shop_order_details(order_id: str) -> List[OrderDetail]:
|
||||
rows = await db.fetchall(
|
||||
f"SELECT * FROM diagonalley.order_details WHERE order_id = ?", (order_id,)
|
||||
f"SELECT * FROM shop.order_details WHERE order_id = ?", (order_id,)
|
||||
)
|
||||
|
||||
return [OrderDetail(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_diagonalley_order(order_id: str) -> Optional[Orders]:
|
||||
async def get_shop_order(order_id: str) -> Optional[Orders]:
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,)
|
||||
"SELECT * FROM shop.orders WHERE id = ?", (order_id,)
|
||||
)
|
||||
return Orders(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_order_invoiceid(invoice_id: str) -> Optional[Orders]:
|
||||
async def get_shop_order_invoiceid(invoice_id: str) -> Optional[Orders]:
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.orders WHERE invoiceid = ?", (invoice_id,)
|
||||
"SELECT * FROM shop.orders WHERE invoiceid = ?", (invoice_id,)
|
||||
)
|
||||
return Orders(**row) if row else None
|
||||
|
||||
|
||||
async def set_diagonalley_order_paid(payment_hash: str) -> Orders:
|
||||
async def set_shop_order_paid(payment_hash: str) -> Orders:
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE diagonalley.orders
|
||||
UPDATE shop.orders
|
||||
SET paid = true
|
||||
WHERE invoiceid = ?
|
||||
""",
|
||||
|
@ -304,10 +304,10 @@ async def set_diagonalley_order_paid(payment_hash: str) -> Orders:
|
|||
)
|
||||
|
||||
|
||||
async def set_diagonalley_order_pubkey(payment_hash: str, pubkey: str):
|
||||
async def set_shop_order_pubkey(payment_hash: str, pubkey: str):
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE diagonalley.orders
|
||||
UPDATE shop.orders
|
||||
SET pubkey = ?
|
||||
WHERE invoiceid = ?
|
||||
""",
|
||||
|
@ -318,7 +318,7 @@ async def set_diagonalley_order_pubkey(payment_hash: str, pubkey: str):
|
|||
)
|
||||
|
||||
|
||||
async def update_diagonalley_product_stock(products):
|
||||
async def update_shop_product_stock(products):
|
||||
|
||||
q = "\n".join(
|
||||
[f"""WHEN id='{p.product_id}' THEN quantity - {p.quantity}""" for p in products]
|
||||
|
@ -327,7 +327,7 @@ async def update_diagonalley_product_stock(products):
|
|||
|
||||
await db.execute(
|
||||
f"""
|
||||
UPDATE diagonalley.products
|
||||
UPDATE shop.products
|
||||
SET quantity=(CASE
|
||||
{q}
|
||||
END)
|
||||
|
@ -337,53 +337,53 @@ async def update_diagonalley_product_stock(products):
|
|||
)
|
||||
|
||||
|
||||
async def get_diagonalley_orders(wallet_ids: Union[str, List[str]]) -> List[Orders]:
|
||||
async def get_shop_orders(wallet_ids: Union[str, List[str]]) -> List[Orders]:
|
||||
if isinstance(wallet_ids, str):
|
||||
wallet_ids = [wallet_ids]
|
||||
|
||||
q = ",".join(["?"] * len(wallet_ids))
|
||||
rows = await db.fetchall(
|
||||
f"SELECT * FROM diagonalley.orders WHERE wallet IN ({q})", (*wallet_ids,)
|
||||
f"SELECT * FROM shop.orders WHERE wallet IN ({q})", (*wallet_ids,)
|
||||
)
|
||||
#
|
||||
return [Orders(**row) for row in rows]
|
||||
|
||||
|
||||
async def delete_diagonalley_order(order_id: str) -> None:
|
||||
await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,))
|
||||
async def delete_shop_order(order_id: str) -> None:
|
||||
await db.execute("DELETE FROM shop.orders WHERE id = ?", (order_id,))
|
||||
|
||||
|
||||
### Market/Marketplace
|
||||
|
||||
|
||||
async def get_diagonalley_markets(user: str) -> List[Market]:
|
||||
rows = await db.fetchall("SELECT * FROM diagonalley.markets WHERE usr = ?", (user,))
|
||||
async def get_shop_markets(user: str) -> List[Market]:
|
||||
rows = await db.fetchall("SELECT * FROM shop.markets WHERE usr = ?", (user,))
|
||||
return [Market(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_diagonalley_market(market_id: str) -> Optional[Market]:
|
||||
async def get_shop_market(market_id: str) -> Optional[Market]:
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.markets WHERE id = ?", (market_id,)
|
||||
"SELECT * FROM shop.markets WHERE id = ?", (market_id,)
|
||||
)
|
||||
return Market(**row) if row else None
|
||||
|
||||
|
||||
async def get_diagonalley_market_stalls(market_id: str):
|
||||
async def get_shop_market_stalls(market_id: str):
|
||||
rows = await db.fetchall(
|
||||
"SELECT * FROM diagonalley.market_stalls WHERE marketid = ?", (market_id,)
|
||||
"SELECT * FROM shop.market_stalls WHERE marketid = ?", (market_id,)
|
||||
)
|
||||
|
||||
ids = [row["stallid"] for row in rows]
|
||||
|
||||
return await get_diagonalley_stalls_by_ids(ids)
|
||||
return await get_shop_stalls_by_ids(ids)
|
||||
|
||||
|
||||
async def create_diagonalley_market(data: CreateMarket):
|
||||
async def create_shop_market(data: CreateMarket):
|
||||
market_id = urlsafe_short_hash()
|
||||
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO diagonalley.markets (id, usr, name)
|
||||
INSERT INTO shop.markets (id, usr, name)
|
||||
VALUES (?, ?, ?)
|
||||
""",
|
||||
(
|
||||
|
@ -392,12 +392,12 @@ async def create_diagonalley_market(data: CreateMarket):
|
|||
data.name,
|
||||
),
|
||||
)
|
||||
market = await get_diagonalley_market(market_id)
|
||||
market = await get_shop_market(market_id)
|
||||
assert market, "Newly created market couldn't be retrieved"
|
||||
return market
|
||||
|
||||
|
||||
async def create_diagonalley_market_stalls(
|
||||
async def create_shop_market_stalls(
|
||||
market_id: str, data: List[CreateMarketStalls]
|
||||
):
|
||||
for stallid in data:
|
||||
|
@ -405,7 +405,7 @@ async def create_diagonalley_market_stalls(
|
|||
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO diagonalley.market_stalls (id, marketid, stallid)
|
||||
INSERT INTO shop.market_stalls (id, marketid, stallid)
|
||||
VALUES (?, ?, ?)
|
||||
""",
|
||||
(
|
||||
|
@ -414,11 +414,11 @@ async def create_diagonalley_market_stalls(
|
|||
stallid,
|
||||
),
|
||||
)
|
||||
market_stalls = await get_diagonalley_market_stalls(market_id)
|
||||
market_stalls = await get_shop_market_stalls(market_id)
|
||||
return market_stalls
|
||||
|
||||
|
||||
async def update_diagonalley_market(market_id):
|
||||
async def update_shop_market(market_id):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -428,7 +428,7 @@ async def update_diagonalley_market(market_id):
|
|||
async def create_chat_message(data: CreateChatMessage):
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO diagonalley.messages (msg, pubkey, id_conversation)
|
||||
INSERT INTO shop.messages (msg, pubkey, id_conversation)
|
||||
VALUES (?, ?, ?)
|
||||
""",
|
||||
(
|
||||
|
@ -439,29 +439,29 @@ async def create_chat_message(data: CreateChatMessage):
|
|||
)
|
||||
|
||||
|
||||
async def get_diagonalley_latest_chat_messages(room_name: str):
|
||||
async def get_shop_latest_chat_messages(room_name: str):
|
||||
rows = await db.fetchall(
|
||||
"SELECT * FROM diagonalley.messages WHERE id_conversation = ? ORDER BY timestamp DESC LIMIT 20",
|
||||
"SELECT * FROM shop.messages WHERE id_conversation = ? ORDER BY timestamp DESC LIMIT 20",
|
||||
(room_name,),
|
||||
)
|
||||
|
||||
return [ChatMessage(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_diagonalley_chat_messages(room_name: str):
|
||||
async def get_shop_chat_messages(room_name: str):
|
||||
rows = await db.fetchall(
|
||||
"SELECT * FROM diagonalley.messages WHERE id_conversation = ? ORDER BY timestamp DESC",
|
||||
"SELECT * FROM shop.messages WHERE id_conversation = ? ORDER BY timestamp DESC",
|
||||
(room_name,),
|
||||
)
|
||||
|
||||
return [ChatMessage(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_diagonalley_chat_by_merchant(ids: List[str]) -> List[ChatMessage]:
|
||||
async def get_shop_chat_by_merchant(ids: List[str]) -> List[ChatMessage]:
|
||||
|
||||
q = ",".join(["?"] * len(ids))
|
||||
rows = await db.fetchall(
|
||||
f"SELECT * FROM diagonalley.messages WHERE id_conversation IN ({q})",
|
||||
f"SELECT * FROM shop.messages WHERE id_conversation IN ({q})",
|
||||
(*ids,),
|
||||
)
|
||||
return [ChatMessage(**row) for row in rows]
|
|
@ -4,7 +4,7 @@ async def m001_initial(db):
|
|||
"""
|
||||
await db.execute(
|
||||
"""
|
||||
CREATE TABLE diagonalley.stalls (
|
||||
CREATE TABLE shop.stalls (
|
||||
id TEXT PRIMARY KEY,
|
||||
wallet TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
|
@ -22,7 +22,7 @@ async def m001_initial(db):
|
|||
"""
|
||||
await db.execute(
|
||||
f"""
|
||||
CREATE TABLE diagonalley.products (
|
||||
CREATE TABLE shop.products (
|
||||
id TEXT PRIMARY KEY,
|
||||
stall TEXT NOT NULL REFERENCES {db.references_schema}stalls (id),
|
||||
product TEXT NOT NULL,
|
||||
|
@ -41,7 +41,7 @@ async def m001_initial(db):
|
|||
"""
|
||||
await db.execute(
|
||||
"""
|
||||
CREATE TABLE diagonalley.zones (
|
||||
CREATE TABLE shop.zones (
|
||||
id TEXT PRIMARY KEY,
|
||||
"user" TEXT NOT NULL,
|
||||
cost TEXT NOT NULL,
|
||||
|
@ -55,7 +55,7 @@ async def m001_initial(db):
|
|||
"""
|
||||
await db.execute(
|
||||
f"""
|
||||
CREATE TABLE diagonalley.orders (
|
||||
CREATE TABLE shop.orders (
|
||||
id {db.serial_primary_key},
|
||||
wallet TEXT NOT NULL,
|
||||
username TEXT,
|
||||
|
@ -79,7 +79,7 @@ async def m001_initial(db):
|
|||
"""
|
||||
await db.execute(
|
||||
f"""
|
||||
CREATE TABLE diagonalley.order_details (
|
||||
CREATE TABLE shop.order_details (
|
||||
id TEXT PRIMARY KEY,
|
||||
order_id INTEGER NOT NULL REFERENCES {db.references_schema}orders (id),
|
||||
product_id TEXT NOT NULL REFERENCES {db.references_schema}products (id),
|
||||
|
@ -93,7 +93,7 @@ async def m001_initial(db):
|
|||
"""
|
||||
await db.execute(
|
||||
"""
|
||||
CREATE TABLE diagonalley.markets (
|
||||
CREATE TABLE shop.markets (
|
||||
id TEXT PRIMARY KEY,
|
||||
usr TEXT NOT NULL,
|
||||
name TEXT
|
||||
|
@ -106,7 +106,7 @@ async def m001_initial(db):
|
|||
"""
|
||||
await db.execute(
|
||||
f"""
|
||||
CREATE TABLE diagonalley.market_stalls (
|
||||
CREATE TABLE shop.market_stalls (
|
||||
id TEXT PRIMARY KEY,
|
||||
marketid TEXT NOT NULL REFERENCES {db.references_schema}markets (id),
|
||||
stallid TEXT NOT NULL REFERENCES {db.references_schema}stalls (id)
|
||||
|
@ -121,7 +121,7 @@ async def m002_add_chat_messages(db):
|
|||
"""
|
||||
await db.execute(
|
||||
f"""
|
||||
CREATE TABLE diagonalley.messages (
|
||||
CREATE TABLE shop.messages (
|
||||
id {db.serial_primary_key},
|
||||
msg TEXT NOT NULL,
|
||||
pubkey TEXT NOT NULL,
|
||||
|
@ -138,8 +138,8 @@ async def m002_add_chat_messages(db):
|
|||
Create indexes for message fetching
|
||||
"""
|
||||
await db.execute(
|
||||
"CREATE INDEX idx_messages_timestamp ON diagonalley.messages (timestamp DESC)"
|
||||
"CREATE INDEX idx_messages_timestamp ON shop.messages (timestamp DESC)"
|
||||
)
|
||||
await db.execute(
|
||||
"CREATE INDEX idx_messages_conversations ON diagonalley.messages (id_conversation)"
|
||||
"CREATE INDEX idx_messages_conversations ON shop.messages (id_conversation)"
|
||||
)
|
|
@ -10,8 +10,8 @@ from collections import defaultdict
|
|||
from fastapi import WebSocket
|
||||
from loguru import logger
|
||||
|
||||
from lnbits.extensions.diagonalley.crud import create_chat_message
|
||||
from lnbits.extensions.diagonalley.models import CreateChatMessage
|
||||
from lnbits.extensions.shop.crud import create_chat_message
|
||||
from lnbits.extensions.shop.models import CreateChatMessage
|
||||
|
||||
|
||||
class Notifier:
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
@ -6,10 +6,10 @@ from lnbits.core.models import Payment
|
|||
from lnbits.tasks import register_invoice_listener
|
||||
|
||||
from .crud import (
|
||||
get_diagonalley_order_details,
|
||||
get_diagonalley_order_invoiceid,
|
||||
set_diagonalley_order_paid,
|
||||
update_diagonalley_product_stock,
|
||||
get_shop_order_details,
|
||||
get_shop_order_invoiceid,
|
||||
set_shop_order_paid,
|
||||
update_shop_product_stock,
|
||||
)
|
||||
|
||||
|
||||
|
@ -23,17 +23,17 @@ async def wait_for_paid_invoices():
|
|||
|
||||
|
||||
async def on_invoice_paid(payment: Payment) -> None:
|
||||
if payment.extra.get("tag") != "diagonalley":
|
||||
if payment.extra.get("tag") != "shop":
|
||||
return
|
||||
|
||||
order = await get_diagonalley_order_invoiceid(payment.payment_hash)
|
||||
order = await get_shop_order_invoiceid(payment.payment_hash)
|
||||
if not order:
|
||||
logger.error("this should never happen", payment)
|
||||
return
|
||||
|
||||
# set order as paid
|
||||
await set_diagonalley_order_paid(payment.payment_hash)
|
||||
await set_shop_order_paid(payment.payment_hash)
|
||||
|
||||
# deduct items sold from stock
|
||||
details = await get_diagonalley_order_details(order.id)
|
||||
await update_diagonalley_product_stock(details)
|
||||
details = await get_shop_order_details(order.id)
|
||||
await update_shop_product_stock(details)
|
|
@ -7,28 +7,24 @@
|
|||
<q-card>
|
||||
<q-card-section>
|
||||
<h5 class="text-subtitle1 q-my-none">
|
||||
Diagon Alley: Decentralised Market-Stalls
|
||||
LNbits Shop (Nostr support coming soon)
|
||||
</h5>
|
||||
<p>Each Stall has its own keys!<br /></p>
|
||||
|
||||
<ol>
|
||||
<li>Create Shipping Zones you're willing to ship to</li>
|
||||
<li>Create a Stall to list yiur products on</li>
|
||||
<li>Create products to put on the Stall</li>
|
||||
<li>
|
||||
List stalls on a simple frontend shop page, or point at Nostr shop
|
||||
client key
|
||||
Take orders
|
||||
</li>
|
||||
<li>
|
||||
Includes chat support!
|
||||
</li>
|
||||
</ol>
|
||||
Make a list of products to sell, point your list of products at a public
|
||||
relay. Buyers browse your products on the relay, and pay you directly.
|
||||
Ratings are managed by the relay. Your stall can be listed in multiple
|
||||
relays, even over TOR, if you wish to be anonymous.<br />
|
||||
More information on the
|
||||
<a href="https://github.com/lnbits/Diagon-Alley">Diagon Alley Protocol</a
|
||||
><br />
|
||||
The first LNbits shop idea 'Diagon Alley' helped create Nostr, and soon this shop extension will have the option to work on Nostr 'Diagon Alley' mode, by the merchant, shop, and buyer all having keys, and data being routed through Nostr relays.
|
||||
<br />
|
||||
<small>
|
||||
Created by, <a href="https://github.com/benarc">Ben Arc</a></small
|
||||
Created by, <a href="https://github.com/talvasconcelos">Tal Vasconcelos</a>, <a href="https://github.com/benarc">Ben Arc</a></small
|
||||
>
|
||||
<!-- </p> -->
|
||||
</q-card-section>
|
||||
|
@ -51,7 +47,7 @@
|
|||
<q-card-section>
|
||||
<code
|
||||
><span class="text-light-blue">GET</span>
|
||||
/diagonalley/api/v1/stall/products/<relay_id></code
|
||||
/shop/api/v1/stall/products/<relay_id></code
|
||||
>
|
||||
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
||||
<h5 class="text-caption q-mt-sm q-mb-none">
|
||||
|
@ -76,7 +72,7 @@
|
|||
<q-card-section>
|
||||
<code
|
||||
><span class="text-light-green">POST</span>
|
||||
/diagonalley/api/v1/stall/order/<relay_id></code
|
||||
/shop/api/v1/stall/order/<relay_id></code
|
||||
>
|
||||
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
||||
<code
|
||||
|
@ -112,7 +108,7 @@
|
|||
<q-card-section>
|
||||
<code
|
||||
><span class="text-light-blue">GET</span>
|
||||
/diagonalley/api/v1/stall/checkshipped/<checking_id></code
|
||||
/shop/api/v1/stall/checkshipped/<checking_id></code
|
||||
>
|
||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||
<h5 class="text-caption q-mt-sm q-mb-none">
|
|
@ -253,6 +253,7 @@
|
|||
>
|
||||
</q-select>
|
||||
<q-input
|
||||
v-if="diagonalley"
|
||||
v-if="keys"
|
||||
filled
|
||||
dense
|
||||
|
@ -260,6 +261,8 @@
|
|||
label="Public Key"
|
||||
></q-input>
|
||||
<q-input
|
||||
|
||||
v-if="diagonalley"
|
||||
v-if="keys"
|
||||
filled
|
||||
dense
|
||||
|
@ -267,7 +270,7 @@
|
|||
label="Private Key"
|
||||
></q-input>
|
||||
<!-- NOSTR -->
|
||||
<div class="row">
|
||||
<div v-if="diagonalley" class="row">
|
||||
<div class="col-5">
|
||||
<q-btn unelevated @click="generateKeys" color="primary"
|
||||
>Generate keys</q-btn
|
||||
|
@ -287,8 +290,8 @@
|
|||
v-model.trim="stallDialog.data.shippingzones"
|
||||
label="Shipping Zones"
|
||||
></q-select>
|
||||
<!-- NOSTR -->
|
||||
<!-- <q-select
|
||||
<q-select
|
||||
v-if="diagonalley"
|
||||
:options="relayOptions"
|
||||
filled
|
||||
dense
|
||||
|
@ -297,21 +300,20 @@
|
|||
label="Relays"
|
||||
></q-select>
|
||||
<q-input
|
||||
v-if="diagonalley"
|
||||
filled
|
||||
dense
|
||||
v-model.trim="stallDialog.data.crelays"
|
||||
label="Custom relays (seperate by comma)"
|
||||
></q-input>
|
||||
|
||||
<q-input
|
||||
v-if="diagonalley"
|
||||
filled
|
||||
dense
|
||||
v-model.trim="stallDialog.data.nostrShops"
|
||||
label="Nostr shop public keys (seperate by comma)"
|
||||
></q-input> -->
|
||||
<p>
|
||||
<strong><small>Nostr support coming soon!</small></strong>
|
||||
</p>
|
||||
></q-input>
|
||||
|
||||
<div class="row q-mt-lg">
|
||||
<q-btn
|
||||
v-if="stallDialog.data.id"
|
||||
|
@ -325,9 +327,7 @@
|
|||
unelevated
|
||||
color="primary"
|
||||
:disable="stallDialog.data.wallet == null
|
||||
|| stallDialog.data.shippingzones == null
|
||||
|| stallDialog.data.publickey == null
|
||||
|| stallDialog.data.privatekey == null"
|
||||
|| stallDialog.data.shippingzones == null"
|
||||
type="submit"
|
||||
>Create Stall</q-btn
|
||||
>
|
||||
|
@ -398,10 +398,9 @@
|
|||
</q-card-section>
|
||||
<q-separator inset></q-separator>
|
||||
<q-card-section>
|
||||
<div class="text-h6">Diagon Alley</div>
|
||||
<div class="text-h6">Shop</div>
|
||||
<div class="text-subtitle2">
|
||||
Step inside the Leaky Cauldron and enter the Diagon Alley. Make this
|
||||
market available on Nostr!
|
||||
Make a shop of multiple stalls.
|
||||
</div>
|
||||
</q-card-section>
|
||||
|
||||
|
@ -423,9 +422,9 @@
|
|||
unelevated
|
||||
color="primary"
|
||||
@click="shopDataDownload"
|
||||
>Download Data
|
||||
>Export all Data
|
||||
<q-tooltip>
|
||||
Download all data (shops, products, orders, etc...)</q-tooltip
|
||||
Export all data (shops, products, orders, etc...)</q-tooltip
|
||||
></q-btn
|
||||
>
|
||||
</q-card-section>
|
||||
|
@ -703,7 +702,7 @@
|
|||
icon="storefront"
|
||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
type="a"
|
||||
:href="'/diagonalley/stalls/' + props.row.id"
|
||||
:href="'/shop/stalls/' + props.row.id"
|
||||
target="_blank"
|
||||
></q-btn>
|
||||
<q-tooltip> Stall simple UI shopping cart </q-tooltip>
|
||||
|
@ -777,7 +776,7 @@
|
|||
icon="storefront"
|
||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
type="a"
|
||||
:href="'/diagonalley/market/' + props.row.id"
|
||||
:href="'/shop/market/' + props.row.id"
|
||||
target="_blank"
|
||||
></q-btn>
|
||||
<q-tooltip> Link to pass to stall relay </q-tooltip>
|
||||
|
@ -921,16 +920,16 @@
|
|||
<q-card>
|
||||
<q-card-section>
|
||||
<h6 class="text-subtitle1 q-my-none">
|
||||
LNbits Diagon Alley Extension, powered by Nostr
|
||||
LNbits Shop Extension, powered by Nostr
|
||||
</h6>
|
||||
</q-card-section>
|
||||
<q-card-section class="q-pa-none">
|
||||
<q-separator></q-separator>
|
||||
<q-list> {% include "diagonalley/_api_docs.html" %} </q-list>
|
||||
<q-list> {% include "shop/_api_docs.html" %} </q-list>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
<!-- CHAT BOX -->
|
||||
<q-card>
|
||||
<q-card style="max-height: 600px">
|
||||
<q-card-section>
|
||||
<h6 class="text-subtitle1 q-my-none">Messages</h6>
|
||||
</q-card-section>
|
||||
|
@ -946,6 +945,7 @@
|
|||
emit-value
|
||||
></q-select>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<div class="chat-container q-pa-md" ref="chatCard">
|
||||
<div class="chat-box">
|
||||
<!-- <p v-if="Object.keys(messages).length === 0">No messages yet</p> -->
|
||||
|
@ -960,6 +960,7 @@
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
<q-card-section>
|
||||
<q-form @submit="sendMessage" class="full-width chat-input">
|
||||
<q-input
|
||||
ref="newMessage"
|
||||
|
@ -981,7 +982,9 @@
|
|||
</template>
|
||||
</q-input>
|
||||
</q-form>
|
||||
</q-card-section>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
<!-- <q-card>
|
||||
<q-card-section>
|
||||
|
@ -1062,7 +1065,7 @@
|
|||
</div>
|
||||
<q-dialog v-model="onboarding.show">
|
||||
<q-card class="q-pa-lg">
|
||||
<h6 class="q-my-md text-primary">How to use Diagon Alley</h6>
|
||||
<h6 class="q-my-md text-primary">How to use Shop</h6>
|
||||
<q-stepper v-model="step" color="primary" vertical animated>
|
||||
<q-step
|
||||
:name="1"
|
||||
|
@ -1155,7 +1158,7 @@
|
|||
obj._data = _.clone(obj)
|
||||
obj.stores = []
|
||||
LNbits.api
|
||||
.request('GET', `/diagonalley/api/v1/markets/${obj.id}/stalls`, null)
|
||||
.request('GET', `/shop/api/v1/markets/${obj.id}/stalls`, null)
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
obj.stores = response.data.map(s => s.name).toString()
|
||||
|
@ -1190,6 +1193,7 @@
|
|||
},
|
||||
keys: null,
|
||||
diagonAlley: false,
|
||||
diagonalley: false,
|
||||
products: [],
|
||||
orders: [],
|
||||
stalls: [],
|
||||
|
@ -1503,7 +1507,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/diagonalley/api/v1/keys',
|
||||
'/shop/api/v1/keys',
|
||||
this.g.user.wallets[0].adminkey
|
||||
)
|
||||
.then(response => {
|
||||
|
@ -1512,7 +1516,7 @@
|
|||
this.stallDialog.data.publickey = this.keys.pubkey
|
||||
this.stallDialog.data.privatekey = this.keys.privkey
|
||||
this.$q.localStorage.set(
|
||||
`lnbits.diagonalley.${this.g.user.id}`,
|
||||
`lnbits.shop.${this.g.user.id}`,
|
||||
this.keys
|
||||
)
|
||||
}
|
||||
|
@ -1523,7 +1527,7 @@
|
|||
},
|
||||
restoreKeys() {
|
||||
let keys = this.$q.localStorage.getItem(
|
||||
`lnbits.diagonalley.${this.g.user.id}`
|
||||
`lnbits.shop.${this.g.user.id}`
|
||||
)
|
||||
if (keys) {
|
||||
this.keys = keys
|
||||
|
@ -1580,7 +1584,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/diagonalley/api/v1/stalls?all_wallets=true',
|
||||
'/shop/api/v1/stalls?all_wallets=true',
|
||||
self.g.user.wallets[0].adminkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -1636,7 +1640,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
'/diagonalley/api/v1/stalls/' + data.id,
|
||||
'/shop/api/v1/stalls/' + data.id,
|
||||
_.findWhere(self.g.user.wallets, {
|
||||
id: self.stallDialog.data.wallet
|
||||
}).inkey,
|
||||
|
@ -1658,7 +1662,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'/diagonalley/api/v1/stalls',
|
||||
'/shop/api/v1/stalls',
|
||||
_.findWhere(self.g.user.wallets, {
|
||||
id: self.stallDialog.data.wallet
|
||||
}).inkey,
|
||||
|
@ -1685,7 +1689,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/diagonalley/api/v1/stalls/' + stallId,
|
||||
'/shop/api/v1/stalls/' + stallId,
|
||||
_.findWhere(self.g.user.wallets, {id: stall.wallet}).adminkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -1710,7 +1714,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/diagonalley/api/v1/products?all_stalls=true',
|
||||
'/shop/api/v1/products?all_stalls=true',
|
||||
self.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -1783,7 +1787,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
'/diagonalley/api/v1/products/' + data.id,
|
||||
'/shop/api/v1/products/' + data.id,
|
||||
_.findWhere(self.g.user.wallets, {
|
||||
id: wallet
|
||||
}).inkey,
|
||||
|
@ -1809,7 +1813,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'/diagonalley/api/v1/products',
|
||||
'/shop/api/v1/products',
|
||||
_.findWhere(self.g.user.wallets, {id: walletId}).inkey,
|
||||
data
|
||||
)
|
||||
|
@ -1831,7 +1835,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/diagonalley/api/v1/products/' + productId,
|
||||
'/shop/api/v1/products/' + productId,
|
||||
_.findWhere(this.g.user.wallets, {id: walletId}).adminkey
|
||||
)
|
||||
.then(() => {
|
||||
|
@ -1856,7 +1860,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/diagonalley/api/v1/zones',
|
||||
'/shop/api/v1/zones',
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -1896,7 +1900,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'/diagonalley/api/v1/zones/' + data.id,
|
||||
'/shop/api/v1/zones/' + data.id,
|
||||
self.g.user.wallets[0].adminkey,
|
||||
data
|
||||
)
|
||||
|
@ -1918,7 +1922,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'/diagonalley/api/v1/zones',
|
||||
'/shop/api/v1/zones',
|
||||
self.g.user.wallets[0].inkey,
|
||||
data
|
||||
)
|
||||
|
@ -1942,7 +1946,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/diagonalley/api/v1/zones/' + zoneId,
|
||||
'/shop/api/v1/zones/' + zoneId,
|
||||
self.g.user.wallets[0].adminkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -1965,7 +1969,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/diagonalley/api/v1/markets',
|
||||
'/shop/api/v1/markets',
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(response => {
|
||||
|
@ -2003,7 +2007,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
'/diagonalley/api/v1/shops' + data.id,
|
||||
'/shop/api/v1/shops' + data.id,
|
||||
_.findWhere(self.g.user.wallets, {
|
||||
id: self.marketDialog.data.wallet
|
||||
}).inkey,
|
||||
|
@ -2026,7 +2030,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'/diagonalley/api/v1/markets',
|
||||
'/shop/api/v1/markets',
|
||||
this.g.user.wallets[0].inkey,
|
||||
data
|
||||
)
|
||||
|
@ -2050,7 +2054,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/diagonalley/api/v1/shops/' + shopId,
|
||||
'/shop/api/v1/shops/' + shopId,
|
||||
_.findWhere(self.g.user.wallets, {id: shop.wallet}).inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -2075,7 +2079,7 @@
|
|||
await LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/diagonalley/api/v1/orders?all_wallets=true',
|
||||
'/shop/api/v1/orders?all_wallets=true',
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -2099,7 +2103,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'/diagonalley/api/v1/orders',
|
||||
'/shop/api/v1/orders',
|
||||
_.findWhere(self.g.user.wallets, {id: self.orderDialog.data.wallet})
|
||||
.inkey,
|
||||
data
|
||||
|
@ -2123,7 +2127,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/diagonalley/api/v1/orders/' + orderId,
|
||||
'/shop/api/v1/orders/' + orderId,
|
||||
_.findWhere(self.g.user.wallets, {id: order.wallet}).adminkey
|
||||
)
|
||||
.then(function (response) {
|
||||
|
@ -2140,7 +2144,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/diagonalley/api/v1/orders/shipped/' + order_id,
|
||||
'/shop/api/v1/orders/shipped/' + order_id,
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(response => {
|
||||
|
@ -2161,7 +2165,7 @@
|
|||
await LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
`/diagonalley/api/v1/chat/messages/merchant?orders=${this.orders
|
||||
`/shop/api/v1/chat/messages/merchant?orders=${this.orders
|
||||
.map(o => o.invoiceid)
|
||||
.toString()}`,
|
||||
this.g.user.wallets[0].adminkey
|
||||
|
@ -2176,7 +2180,7 @@
|
|||
},
|
||||
updateLastSeenMsg(id) {
|
||||
let data = this.$q.localStorage.getItem(
|
||||
`lnbits.diagonalley.${this.g.user.id}`
|
||||
`lnbits.shop.${this.g.user.id}`
|
||||
)
|
||||
let chat = {
|
||||
...data.chat,
|
||||
|
@ -2186,7 +2190,7 @@
|
|||
]
|
||||
}
|
||||
}
|
||||
this.$q.localStorage.set(`lnbits.diagonalley.${this.g.user.id}`, {
|
||||
this.$q.localStorage.set(`lnbits.shop.${this.g.user.id}`, {
|
||||
...data,
|
||||
chat
|
||||
})
|
||||
|
@ -2194,7 +2198,7 @@
|
|||
},
|
||||
checkUnreadMessages() {
|
||||
let lastMsgs = this.$q.localStorage.getItem(
|
||||
`lnbits.diagonalley.${this.g.user.id}`
|
||||
`lnbits.shop.${this.g.user.id}`
|
||||
).chat
|
||||
for (let key in this.messages) {
|
||||
let idx = this.orders.findIndex(f => f.invoiceid == key)
|
||||
|
@ -2253,14 +2257,14 @@
|
|||
ws_scheme = 'ws://'
|
||||
}
|
||||
ws = new WebSocket(
|
||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
||||
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||
)
|
||||
|
||||
function checkWebSocket(event) {
|
||||
if (ws.readyState === WebSocket.CLOSED) {
|
||||
console.log('WebSocket CLOSED: Reopening')
|
||||
ws = new WebSocket(
|
||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
||||
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -2293,7 +2297,7 @@
|
|||
this.getMarkets()
|
||||
await this.getAllMessages()
|
||||
let keys = this.$q.localStorage.getItem(
|
||||
`lnbits.diagonalley.${this.g.user.id}`
|
||||
`lnbits.shop.${this.g.user.id}`
|
||||
)
|
||||
if (keys) {
|
||||
this.keys = keys
|
|
@ -76,7 +76,7 @@
|
|||
<q-card class="card--product">
|
||||
{% raw %}
|
||||
<q-img
|
||||
:src="item.image ? item.image : '/diagonalley/static/images/placeholder.png'"
|
||||
:src="item.image ? item.image : '/shop/static/images/placeholder.png'"
|
||||
alt="Product Image"
|
||||
loading="lazy"
|
||||
spinner-color="white"
|
||||
|
@ -357,7 +357,7 @@
|
|||
})
|
||||
}
|
||||
LNbits.api
|
||||
.request('POST', '/diagonalley/api/v1/orders', null, data)
|
||||
.request('POST', '/shop/api/v1/orders', null, data)
|
||||
.then(res => {
|
||||
this.checkoutDialog = {show: false, data: {}}
|
||||
|
||||
|
@ -378,7 +378,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
`/diagonalley/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
||||
`/shop/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
||||
)
|
||||
.then(res => {
|
||||
if (res.data.paid) {
|
|
@ -102,7 +102,7 @@
|
|||
<q-card-section>
|
||||
<q-separator></q-separator>
|
||||
<q-list>
|
||||
<q-expansion-item group="extras" icon="vpn_key" label="Keys"
|
||||
<q-expansion-item v-if="diagonalley" group="extras" icon="vpn_key" label="Keys"
|
||||
><p>
|
||||
Bellow are the keys needed to contact the merchant. They are
|
||||
stored in the browser!
|
||||
|
@ -197,6 +197,7 @@
|
|||
</div>
|
||||
<!-- RESTORE KEYS DIALOG -->
|
||||
<q-dialog
|
||||
v-if="diagonalley"
|
||||
v-model="keysDialog.show"
|
||||
position="top"
|
||||
@hide="clearRestoreKeyDialog"
|
||||
|
@ -258,6 +259,7 @@
|
|||
messages: {},
|
||||
stall: null,
|
||||
selectedOrder: null,
|
||||
diagonalley: false,
|
||||
products: [],
|
||||
orders: [],
|
||||
user: {
|
||||
|
@ -320,8 +322,8 @@
|
|||
},
|
||||
restoreKeys() {
|
||||
this.user.keys = this.keysDialog.data
|
||||
let data = this.$q.localStorage.getItem(`lnbits.diagonalley.data`)
|
||||
this.$q.localStorage.set(`lnbits.diagonalley.data`, {
|
||||
let data = this.$q.localStorage.getItem(`lnbits.shop.data`)
|
||||
this.$q.localStorage.set(`lnbits.shop.data`, {
|
||||
...data,
|
||||
keys: this.user.keys
|
||||
})
|
||||
|
@ -332,7 +334,7 @@
|
|||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete your stored data?')
|
||||
.onOk(() => {
|
||||
this.$q.localStorage.remove('lnbits.diagonalley.data')
|
||||
this.$q.localStorage.remove('lnbits.shop.data')
|
||||
this.user = null
|
||||
})
|
||||
},
|
||||
|
@ -342,7 +344,7 @@
|
|||
return
|
||||
|
||||
return await LNbits.api
|
||||
.request('GET', `/diagonalley/api/v1/keys`, null)
|
||||
.request('GET', `/shop/api/v1/keys`, null)
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
let data = {
|
||||
|
@ -363,7 +365,7 @@
|
|||
await LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
`/diagonalley/api/v1/chat/messages/${room_name}${
|
||||
`/shop/api/v1/chat/messages/${room_name}${
|
||||
all ? '?all_messages=true' : ''
|
||||
}`
|
||||
)
|
||||
|
@ -397,14 +399,14 @@
|
|||
ws_scheme = 'ws://'
|
||||
}
|
||||
ws = new WebSocket(
|
||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
||||
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||
)
|
||||
|
||||
function checkWebSocket(event) {
|
||||
if (ws.readyState === WebSocket.CLOSED) {
|
||||
console.log('WebSocket CLOSED: Reopening')
|
||||
ws = new WebSocket(
|
||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
||||
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -447,7 +449,7 @@
|
|||
})
|
||||
|
||||
let data =
|
||||
this.$q.localStorage.getItem(`lnbits.diagonalley.data`) || false
|
||||
this.$q.localStorage.getItem(`lnbits.shop.data`) || false
|
||||
|
||||
if (data) {
|
||||
this.user = data
|
||||
|
@ -468,7 +470,7 @@
|
|||
|
||||
await this.getMessages(order_id)
|
||||
|
||||
this.$q.localStorage.set(`lnbits.diagonalley.data`, this.user)
|
||||
this.$q.localStorage.set(`lnbits.shop.data`, this.user)
|
||||
this.startChat(order_id)
|
||||
}
|
||||
})
|
|
@ -76,7 +76,7 @@
|
|||
<q-card class="card--product">
|
||||
{% raw %}
|
||||
<q-img
|
||||
:src="item.image ? item.image : '/diagonalley/static/images/placeholder.png'"
|
||||
:src="item.image ? item.image : '/shop/static/images/placeholder.png'"
|
||||
alt="Product Image"
|
||||
loading="lazy"
|
||||
spinner-color="white"
|
||||
|
@ -163,6 +163,7 @@
|
|||
label="Name *optional"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="diagonalley"
|
||||
filled
|
||||
dense
|
||||
v-model.trim="checkoutDialog.data.pubkey"
|
||||
|
@ -279,6 +280,7 @@
|
|||
stall: null,
|
||||
products: [],
|
||||
searchText: null,
|
||||
diagonalley:false,
|
||||
cart: {
|
||||
total: 0,
|
||||
size: 0,
|
||||
|
@ -364,7 +366,7 @@
|
|||
})
|
||||
},
|
||||
getPubkey() {
|
||||
let data = this.$q.localStorage.getItem(`lnbits.diagonalley.data`)
|
||||
let data = this.$q.localStorage.getItem(`lnbits.shop.data`)
|
||||
if (data && data.keys.publickey) {
|
||||
this.checkoutDialog.data.pubkey = data.keys.publickey
|
||||
} else {
|
||||
|
@ -386,7 +388,7 @@
|
|||
})
|
||||
}
|
||||
LNbits.api
|
||||
.request('POST', '/diagonalley/api/v1/orders', null, data)
|
||||
.request('POST', '/shop/api/v1/orders', null, data)
|
||||
.then(res => {
|
||||
this.checkoutDialog = {show: false, data: {}}
|
||||
|
||||
|
@ -407,7 +409,7 @@
|
|||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
`/diagonalley/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
||||
`/shop/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
||||
)
|
||||
.then(res => {
|
||||
if (res.data.paid) {
|
||||
|
@ -421,7 +423,7 @@
|
|||
{
|
||||
label: 'See Order',
|
||||
handler: () => {
|
||||
window.location.href = `/diagonalley/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
|
||||
window.location.href = `/shop/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -430,7 +432,7 @@
|
|||
this.resetCart()
|
||||
this.closeQrCodeDialog()
|
||||
setTimeout(() => {
|
||||
window.location.href = `/diagonalley/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
|
||||
window.location.href = `/shop/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
|
||||
}, 5000)
|
||||
}
|
||||
})
|
|
@ -11,40 +11,40 @@ from starlette.responses import HTMLResponse
|
|||
|
||||
from lnbits.core.models import User
|
||||
from lnbits.decorators import check_user_exists # type: ignore
|
||||
from lnbits.extensions.diagonalley import diagonalley_ext, diagonalley_renderer
|
||||
from lnbits.extensions.diagonalley.models import CreateChatMessage
|
||||
from lnbits.extensions.diagonalley.notifier import Notifier
|
||||
from lnbits.extensions.shop import shop_ext, shop_renderer
|
||||
from lnbits.extensions.shop.models import CreateChatMessage
|
||||
from lnbits.extensions.shop.notifier import Notifier
|
||||
|
||||
from .crud import (
|
||||
create_chat_message,
|
||||
get_diagonalley_market,
|
||||
get_diagonalley_market_stalls,
|
||||
get_diagonalley_order_details,
|
||||
get_diagonalley_order_invoiceid,
|
||||
get_diagonalley_products,
|
||||
get_diagonalley_stall,
|
||||
get_diagonalley_zone,
|
||||
get_diagonalley_zones,
|
||||
update_diagonalley_product_stock,
|
||||
get_shop_market,
|
||||
get_shop_market_stalls,
|
||||
get_shop_order_details,
|
||||
get_shop_order_invoiceid,
|
||||
get_shop_products,
|
||||
get_shop_stall,
|
||||
get_shop_zone,
|
||||
get_shop_zones,
|
||||
update_shop_product_stock,
|
||||
)
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@diagonalley_ext.get("/", response_class=HTMLResponse)
|
||||
@shop_ext.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||
return diagonalley_renderer().TemplateResponse(
|
||||
"diagonalley/index.html", {"request": request, "user": user.dict()}
|
||||
return shop_renderer().TemplateResponse(
|
||||
"shop/index.html", {"request": request, "user": user.dict()}
|
||||
)
|
||||
|
||||
|
||||
@diagonalley_ext.get("/stalls/{stall_id}", response_class=HTMLResponse)
|
||||
@shop_ext.get("/stalls/{stall_id}", response_class=HTMLResponse)
|
||||
async def display(request: Request, stall_id):
|
||||
stall = await get_diagonalley_stall(stall_id)
|
||||
products = await get_diagonalley_products(stall_id)
|
||||
stall = await get_shop_stall(stall_id)
|
||||
products = await get_shop_products(stall_id)
|
||||
zones = []
|
||||
for id in stall.shippingzones.split(","):
|
||||
z = await get_diagonalley_zone(id)
|
||||
z = await get_shop_zone(id)
|
||||
z = z.dict()
|
||||
zones.append({"label": z["countries"], "cost": z["cost"], "value": z["id"]})
|
||||
|
||||
|
@ -57,8 +57,8 @@ async def display(request: Request, stall_id):
|
|||
del stall["privatekey"]
|
||||
stall["zones"] = zones
|
||||
|
||||
return diagonalley_renderer().TemplateResponse(
|
||||
"diagonalley/stall.html",
|
||||
return shop_renderer().TemplateResponse(
|
||||
"shop/stall.html",
|
||||
{
|
||||
"request": request,
|
||||
"stall": stall,
|
||||
|
@ -67,23 +67,23 @@ async def display(request: Request, stall_id):
|
|||
)
|
||||
|
||||
|
||||
@diagonalley_ext.get("/market/{market_id}", response_class=HTMLResponse)
|
||||
@shop_ext.get("/market/{market_id}", response_class=HTMLResponse)
|
||||
async def display(request: Request, market_id):
|
||||
market = await get_diagonalley_market(market_id)
|
||||
market = await get_shop_market(market_id)
|
||||
|
||||
if not market:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Marketplace doesn't exist."
|
||||
)
|
||||
|
||||
stalls = await get_diagonalley_market_stalls(market_id)
|
||||
stalls = await get_shop_market_stalls(market_id)
|
||||
stalls_ids = [stall.id for stall in stalls]
|
||||
products = [
|
||||
product.dict() for product in await get_diagonalley_products(stalls_ids)
|
||||
product.dict() for product in await get_shop_products(stalls_ids)
|
||||
]
|
||||
|
||||
return diagonalley_renderer().TemplateResponse(
|
||||
"diagonalley/market.html",
|
||||
return shop_renderer().TemplateResponse(
|
||||
"shop/market.html",
|
||||
{
|
||||
"request": request,
|
||||
"market": market,
|
||||
|
@ -93,20 +93,20 @@ async def display(request: Request, market_id):
|
|||
)
|
||||
|
||||
|
||||
@diagonalley_ext.get("/order", response_class=HTMLResponse)
|
||||
@shop_ext.get("/order", response_class=HTMLResponse)
|
||||
async def chat_page(
|
||||
request: Request,
|
||||
merch: str = Query(...),
|
||||
invoice_id: str = Query(...),
|
||||
keys: str = Query(None),
|
||||
):
|
||||
stall = await get_diagonalley_stall(merch)
|
||||
order = await get_diagonalley_order_invoiceid(invoice_id)
|
||||
_order = await get_diagonalley_order_details(order.id)
|
||||
products = await get_diagonalley_products(stall.id)
|
||||
stall = await get_shop_stall(merch)
|
||||
order = await get_shop_order_invoiceid(invoice_id)
|
||||
_order = await get_shop_order_details(order.id)
|
||||
products = await get_shop_products(stall.id)
|
||||
|
||||
return diagonalley_renderer().TemplateResponse(
|
||||
"diagonalley/order.html",
|
||||
return shop_renderer().TemplateResponse(
|
||||
"shop/order.html",
|
||||
{
|
||||
"request": request,
|
||||
"stall": {
|
||||
|
@ -155,7 +155,7 @@ notifier = Notifier()
|
|||
# manager = ConnectionManager()
|
||||
|
||||
|
||||
# @diagonalley_ext.websocket("/ws/{room_name}")
|
||||
# @shop_ext.websocket("/ws/{room_name}")
|
||||
# async def websocket_endpoint(websocket: WebSocket, room_name: str):
|
||||
# await manager.connect(websocket, room_name)
|
||||
# try:
|
||||
|
@ -165,7 +165,7 @@ notifier = Notifier()
|
|||
# manager.disconnect(websocket)
|
||||
|
||||
|
||||
@diagonalley_ext.websocket("/ws/{room_name}")
|
||||
@shop_ext.websocket("/ws/{room_name}")
|
||||
async def websocket_endpoint(
|
||||
websocket: WebSocket, room_name: str, background_tasks: BackgroundTasks
|
||||
):
|
|
@ -21,41 +21,41 @@ from lnbits.decorators import (
|
|||
)
|
||||
|
||||
from ...helpers import urlsafe_short_hash
|
||||
from . import db, diagonalley_ext
|
||||
from . import db, shop_ext
|
||||
from .crud import (
|
||||
create_diagonalley_market,
|
||||
create_diagonalley_market_stalls,
|
||||
create_diagonalley_order,
|
||||
create_diagonalley_order_details,
|
||||
create_diagonalley_product,
|
||||
create_diagonalley_stall,
|
||||
create_diagonalley_zone,
|
||||
delete_diagonalley_order,
|
||||
delete_diagonalley_product,
|
||||
delete_diagonalley_stall,
|
||||
delete_diagonalley_zone,
|
||||
get_diagonalley_chat_by_merchant,
|
||||
get_diagonalley_chat_messages,
|
||||
get_diagonalley_latest_chat_messages,
|
||||
get_diagonalley_market,
|
||||
get_diagonalley_market_stalls,
|
||||
get_diagonalley_markets,
|
||||
get_diagonalley_order,
|
||||
get_diagonalley_order_details,
|
||||
get_diagonalley_order_invoiceid,
|
||||
get_diagonalley_orders,
|
||||
get_diagonalley_product,
|
||||
get_diagonalley_products,
|
||||
get_diagonalley_stall,
|
||||
get_diagonalley_stalls,
|
||||
get_diagonalley_stalls_by_ids,
|
||||
get_diagonalley_zone,
|
||||
get_diagonalley_zones,
|
||||
set_diagonalley_order_pubkey,
|
||||
update_diagonalley_market,
|
||||
update_diagonalley_product,
|
||||
update_diagonalley_stall,
|
||||
update_diagonalley_zone,
|
||||
create_shop_market,
|
||||
create_shop_market_stalls,
|
||||
create_shop_order,
|
||||
create_shop_order_details,
|
||||
create_shop_product,
|
||||
create_shop_stall,
|
||||
create_shop_zone,
|
||||
delete_shop_order,
|
||||
delete_shop_product,
|
||||
delete_shop_stall,
|
||||
delete_shop_zone,
|
||||
get_shop_chat_by_merchant,
|
||||
get_shop_chat_messages,
|
||||
get_shop_latest_chat_messages,
|
||||
get_shop_market,
|
||||
get_shop_market_stalls,
|
||||
get_shop_markets,
|
||||
get_shop_order,
|
||||
get_shop_order_details,
|
||||
get_shop_order_invoiceid,
|
||||
get_shop_orders,
|
||||
get_shop_product,
|
||||
get_shop_products,
|
||||
get_shop_stall,
|
||||
get_shop_stalls,
|
||||
get_shop_stalls_by_ids,
|
||||
get_shop_zone,
|
||||
get_shop_zones,
|
||||
set_shop_order_pubkey,
|
||||
update_shop_market,
|
||||
update_shop_product,
|
||||
update_shop_stall,
|
||||
update_shop_zone,
|
||||
)
|
||||
from .models import (
|
||||
CreateMarket,
|
||||
|
@ -73,8 +73,8 @@ from .models import (
|
|||
|
||||
|
||||
### Products
|
||||
@diagonalley_ext.get("/api/v1/products")
|
||||
async def api_diagonalley_products(
|
||||
@shop_ext.get("/api/v1/products")
|
||||
async def api_shop_products(
|
||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||
all_stalls: bool = Query(False),
|
||||
):
|
||||
|
@ -83,90 +83,90 @@ async def api_diagonalley_products(
|
|||
if all_stalls:
|
||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||
|
||||
stalls = [stall.id for stall in await get_diagonalley_stalls(wallet_ids)]
|
||||
stalls = [stall.id for stall in await get_shop_stalls(wallet_ids)]
|
||||
|
||||
if not stalls:
|
||||
return
|
||||
|
||||
return [product.dict() for product in await get_diagonalley_products(stalls)]
|
||||
return [product.dict() for product in await get_shop_products(stalls)]
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/products")
|
||||
@diagonalley_ext.put("/api/v1/products/{product_id}")
|
||||
async def api_diagonalley_product_create(
|
||||
@shop_ext.post("/api/v1/products")
|
||||
@shop_ext.put("/api/v1/products/{product_id}")
|
||||
async def api_shop_product_create(
|
||||
data: createProduct, product_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
|
||||
if product_id:
|
||||
product = await get_diagonalley_product(product_id)
|
||||
product = await get_shop_product(product_id)
|
||||
if not product:
|
||||
return {"message": "Withdraw product does not exist."}
|
||||
|
||||
stall = await get_diagonalley_stall(stall_id=product.stall)
|
||||
stall = await get_shop_stall(stall_id=product.stall)
|
||||
if stall.wallet != wallet.wallet.id:
|
||||
return {"message": "Not your withdraw product."}
|
||||
|
||||
product = await update_diagonalley_product(product_id, **data.dict())
|
||||
product = await update_shop_product(product_id, **data.dict())
|
||||
else:
|
||||
product = await create_diagonalley_product(data=data)
|
||||
product = await create_shop_product(data=data)
|
||||
|
||||
return product.dict()
|
||||
|
||||
|
||||
@diagonalley_ext.delete("/api/v1/products/{product_id}")
|
||||
async def api_diagonalley_products_delete(
|
||||
@shop_ext.delete("/api/v1/products/{product_id}")
|
||||
async def api_shop_products_delete(
|
||||
product_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
):
|
||||
product = await get_diagonalley_product(product_id)
|
||||
product = await get_shop_product(product_id)
|
||||
|
||||
if not product:
|
||||
return {"message": "Product does not exist."}
|
||||
|
||||
stall = await get_diagonalley_stall(product.stall)
|
||||
stall = await get_shop_stall(product.stall)
|
||||
if stall.wallet != wallet.wallet.id:
|
||||
return {"message": "Not your Diagon Alley."}
|
||||
return {"message": "Not your Shop."}
|
||||
|
||||
await delete_diagonalley_product(product_id)
|
||||
await delete_shop_product(product_id)
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
# # # Shippingzones
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/zones")
|
||||
async def api_diagonalley_zones(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
@shop_ext.get("/api/v1/zones")
|
||||
async def api_shop_zones(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
|
||||
return await get_diagonalley_zones(wallet.wallet.user)
|
||||
return await get_shop_zones(wallet.wallet.user)
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/zones")
|
||||
async def api_diagonalley_zone_create(
|
||||
@shop_ext.post("/api/v1/zones")
|
||||
async def api_shop_zone_create(
|
||||
data: createZones, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
zone = await create_diagonalley_zone(user=wallet.wallet.user, data=data)
|
||||
zone = await create_shop_zone(user=wallet.wallet.user, data=data)
|
||||
return zone.dict()
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/zones/{zone_id}")
|
||||
async def api_diagonalley_zone_update(
|
||||
@shop_ext.post("/api/v1/zones/{zone_id}")
|
||||
async def api_shop_zone_update(
|
||||
data: createZones,
|
||||
zone_id: str,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
):
|
||||
zone = await get_diagonalley_zone(zone_id)
|
||||
zone = await get_shop_zone(zone_id)
|
||||
if not zone:
|
||||
return {"message": "Zone does not exist."}
|
||||
if zone.user != wallet.wallet.user:
|
||||
return {"message": "Not your record."}
|
||||
zone = await update_diagonalley_zone(zone_id, **data.dict())
|
||||
zone = await update_shop_zone(zone_id, **data.dict())
|
||||
return zone
|
||||
|
||||
|
||||
@diagonalley_ext.delete("/api/v1/zones/{zone_id}")
|
||||
async def api_diagonalley_zone_delete(
|
||||
@shop_ext.delete("/api/v1/zones/{zone_id}")
|
||||
async def api_shop_zone_delete(
|
||||
zone_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
):
|
||||
zone = await get_diagonalley_zone(zone_id)
|
||||
zone = await get_shop_zone(zone_id)
|
||||
|
||||
if not zone:
|
||||
return {"message": "zone does not exist."}
|
||||
|
@ -174,15 +174,15 @@ async def api_diagonalley_zone_delete(
|
|||
if zone.user != wallet.wallet.user:
|
||||
return {"message": "Not your zone."}
|
||||
|
||||
await delete_diagonalley_zone(zone_id)
|
||||
await delete_shop_zone(zone_id)
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
# # # Stalls
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/stalls")
|
||||
async def api_diagonalley_stalls(
|
||||
@shop_ext.get("/api/v1/stalls")
|
||||
async def api_shop_stalls(
|
||||
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
||||
):
|
||||
wallet_ids = [wallet.wallet.id]
|
||||
|
@ -190,37 +190,37 @@ async def api_diagonalley_stalls(
|
|||
if all_wallets:
|
||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||
|
||||
return [stall.dict() for stall in await get_diagonalley_stalls(wallet_ids)]
|
||||
return [stall.dict() for stall in await get_shop_stalls(wallet_ids)]
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/stalls")
|
||||
@diagonalley_ext.put("/api/v1/stalls/{stall_id}")
|
||||
async def api_diagonalley_stall_create(
|
||||
@shop_ext.post("/api/v1/stalls")
|
||||
@shop_ext.put("/api/v1/stalls/{stall_id}")
|
||||
async def api_shop_stall_create(
|
||||
data: createStalls,
|
||||
stall_id: str = None,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
|
||||
if stall_id:
|
||||
stall = await get_diagonalley_stall(stall_id)
|
||||
stall = await get_shop_stall(stall_id)
|
||||
if not stall:
|
||||
return {"message": "Withdraw stall does not exist."}
|
||||
|
||||
if stall.wallet != wallet.wallet.id:
|
||||
return {"message": "Not your withdraw stall."}
|
||||
|
||||
stall = await update_diagonalley_stall(stall_id, **data.dict())
|
||||
stall = await update_shop_stall(stall_id, **data.dict())
|
||||
else:
|
||||
stall = await create_diagonalley_stall(data=data)
|
||||
stall = await create_shop_stall(data=data)
|
||||
|
||||
return stall.dict()
|
||||
|
||||
|
||||
@diagonalley_ext.delete("/api/v1/stalls/{stall_id}")
|
||||
async def api_diagonalley_stall_delete(
|
||||
@shop_ext.delete("/api/v1/stalls/{stall_id}")
|
||||
async def api_shop_stall_delete(
|
||||
stall_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
):
|
||||
stall = await get_diagonalley_stall(stall_id)
|
||||
stall = await get_shop_stall(stall_id)
|
||||
|
||||
if not stall:
|
||||
return {"message": "Stall does not exist."}
|
||||
|
@ -228,44 +228,44 @@ async def api_diagonalley_stall_delete(
|
|||
if stall.wallet != wallet.wallet.id:
|
||||
return {"message": "Not your Stall."}
|
||||
|
||||
await delete_diagonalley_stall(stall_id)
|
||||
await delete_shop_stall(stall_id)
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
###Orders
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/orders")
|
||||
async def api_diagonalley_orders(
|
||||
@shop_ext.get("/api/v1/orders")
|
||||
async def api_shop_orders(
|
||||
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
||||
):
|
||||
wallet_ids = [wallet.wallet.id]
|
||||
if all_wallets:
|
||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||
|
||||
orders = await get_diagonalley_orders(wallet_ids)
|
||||
orders = await get_shop_orders(wallet_ids)
|
||||
orders_with_details = []
|
||||
for order in orders:
|
||||
order = order.dict()
|
||||
order["details"] = await get_diagonalley_order_details(order["id"])
|
||||
order["details"] = await get_shop_order_details(order["id"])
|
||||
orders_with_details.append(order)
|
||||
try:
|
||||
return orders_with_details # [order for order in orders]
|
||||
# return [order.dict() for order in await get_diagonalley_orders(wallet_ids)]
|
||||
# return [order.dict() for order in await get_shop_orders(wallet_ids)]
|
||||
except:
|
||||
return {"message": "We could not retrieve the orders."}
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/orders/{order_id}")
|
||||
async def api_diagonalley_order_by_id(order_id: str):
|
||||
order = (await get_diagonalley_order(order_id)).dict()
|
||||
order["details"] = await get_diagonalley_order_details(order_id)
|
||||
@shop_ext.get("/api/v1/orders/{order_id}")
|
||||
async def api_shop_order_by_id(order_id: str):
|
||||
order = (await get_shop_order(order_id)).dict()
|
||||
order["details"] = await get_shop_order_details(order_id)
|
||||
|
||||
return order
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/orders")
|
||||
async def api_diagonalley_order_create(data: createOrder):
|
||||
@shop_ext.post("/api/v1/orders")
|
||||
async def api_shop_order_create(data: createOrder):
|
||||
ref = urlsafe_short_hash()
|
||||
|
||||
payment_hash, payment_request = await create_invoice(
|
||||
|
@ -273,14 +273,14 @@ async def api_diagonalley_order_create(data: createOrder):
|
|||
amount=data.total,
|
||||
memo=f"New order on Diagon alley",
|
||||
extra={
|
||||
"tag": "diagonalley",
|
||||
"tag": "shop",
|
||||
"reference": ref,
|
||||
},
|
||||
)
|
||||
order_id = await create_diagonalley_order(invoiceid=payment_hash, data=data)
|
||||
order_id = await create_shop_order(invoiceid=payment_hash, data=data)
|
||||
logger.debug(f"ORDER ID {order_id}")
|
||||
logger.debug(f"PRODUCTS {data.products}")
|
||||
await create_diagonalley_order_details(order_id=order_id, data=data.products)
|
||||
await create_shop_order_details(order_id=order_id, data=data.products)
|
||||
return {
|
||||
"payment_hash": payment_hash,
|
||||
"payment_request": payment_request,
|
||||
|
@ -288,9 +288,9 @@ async def api_diagonalley_order_create(data: createOrder):
|
|||
}
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/orders/payments/{payment_hash}")
|
||||
async def api_diagonalley_check_payment(payment_hash: str):
|
||||
order = await get_diagonalley_order_invoiceid(payment_hash)
|
||||
@shop_ext.get("/api/v1/orders/payments/{payment_hash}")
|
||||
async def api_shop_check_payment(payment_hash: str):
|
||||
order = await get_shop_order_invoiceid(payment_hash)
|
||||
if not order:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Order does not exist."
|
||||
|
@ -304,11 +304,11 @@ async def api_diagonalley_check_payment(payment_hash: str):
|
|||
return status
|
||||
|
||||
|
||||
@diagonalley_ext.delete("/api/v1/orders/{order_id}")
|
||||
async def api_diagonalley_order_delete(
|
||||
@shop_ext.delete("/api/v1/orders/{order_id}")
|
||||
async def api_shop_order_delete(
|
||||
order_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
):
|
||||
order = await get_diagonalley_order(order_id)
|
||||
order = await get_shop_order(order_id)
|
||||
|
||||
if not order:
|
||||
return {"message": "Order does not exist."}
|
||||
|
@ -316,17 +316,17 @@ async def api_diagonalley_order_delete(
|
|||
if order.wallet != wallet.wallet.id:
|
||||
return {"message": "Not your Order."}
|
||||
|
||||
await delete_diagonalley_order(order_id)
|
||||
await delete_shop_order(order_id)
|
||||
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/orders/paid/{order_id}")
|
||||
async def api_diagonalley_order_paid(
|
||||
@shop_ext.get("/api/v1/orders/paid/{order_id}")
|
||||
async def api_shop_order_paid(
|
||||
order_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
):
|
||||
await db.execute(
|
||||
"UPDATE diagonalley.orders SET paid = ? WHERE id = ?",
|
||||
"UPDATE shop.orders SET paid = ? WHERE id = ?",
|
||||
(
|
||||
True,
|
||||
order_id,
|
||||
|
@ -335,19 +335,19 @@ async def api_diagonalley_order_paid(
|
|||
return "", HTTPStatus.OK
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/orders/shipped/{order_id}")
|
||||
async def api_diagonalley_order_shipped(
|
||||
@shop_ext.get("/api/v1/orders/shipped/{order_id}")
|
||||
async def api_shop_order_shipped(
|
||||
order_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
await db.execute(
|
||||
"UPDATE diagonalley.orders SET shipped = ? WHERE id = ?",
|
||||
"UPDATE shop.orders SET shipped = ? WHERE id = ?",
|
||||
(
|
||||
True,
|
||||
order_id,
|
||||
),
|
||||
)
|
||||
order = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,)
|
||||
"SELECT * FROM shop.orders WHERE id = ?", (order_id,)
|
||||
)
|
||||
|
||||
return order
|
||||
|
@ -356,35 +356,35 @@ async def api_diagonalley_order_shipped(
|
|||
###List products based on stall id
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/stall/products/{stall_id}")
|
||||
async def api_diagonalley_stall_products(
|
||||
@shop_ext.get("/api/v1/stall/products/{stall_id}")
|
||||
async def api_shop_stall_products(
|
||||
stall_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
|
||||
rows = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.stalls WHERE id = ?", (stall_id,)
|
||||
"SELECT * FROM shop.stalls WHERE id = ?", (stall_id,)
|
||||
)
|
||||
if not rows:
|
||||
return {"message": "Stall does not exist."}
|
||||
|
||||
products = db.fetchone(
|
||||
"SELECT * FROM diagonalley.products WHERE wallet = ?", (rows[1],)
|
||||
"SELECT * FROM shop.products WHERE wallet = ?", (rows[1],)
|
||||
)
|
||||
if not products:
|
||||
return {"message": "No products"}
|
||||
|
||||
return [products.dict() for products in await get_diagonalley_products(rows[1])]
|
||||
return [products.dict() for products in await get_shop_products(rows[1])]
|
||||
|
||||
|
||||
###Check a product has been shipped
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/stall/checkshipped/{checking_id}")
|
||||
async def api_diagonalley_stall_checkshipped(
|
||||
@shop_ext.get("/api/v1/stall/checkshipped/{checking_id}")
|
||||
async def api_shop_stall_checkshipped(
|
||||
checking_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
rows = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.orders WHERE invoiceid = ?", (checking_id,)
|
||||
"SELECT * FROM shop.orders WHERE invoiceid = ?", (checking_id,)
|
||||
)
|
||||
return {"shipped": rows["shipped"]}
|
||||
|
||||
|
@ -392,12 +392,12 @@ async def api_diagonalley_stall_checkshipped(
|
|||
###Place order
|
||||
|
||||
|
||||
# @diagonalley_ext.post("/api/v1/stall/order/{stall_id}")
|
||||
# async def api_diagonalley_stall_order(
|
||||
# @shop_ext.post("/api/v1/stall/order/{stall_id}")
|
||||
# async def api_shop_stall_order(
|
||||
# stall_id, data: createOrder, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
# ):
|
||||
# product = await get_diagonalley_product(data.productid)
|
||||
# shipping = await get_diagonalley_stall(stall_id)
|
||||
# product = await get_shop_product(data.productid)
|
||||
# shipping = await get_shop_stall(stall_id)
|
||||
|
||||
# if data.shippingzone == 1:
|
||||
# shippingcost = shipping.zone1cost # missing in model
|
||||
|
@ -412,7 +412,7 @@ async def api_diagonalley_stall_checkshipped(
|
|||
# selling_id = urlsafe_b64encode(uuid4().bytes_le).decode("utf-8")
|
||||
# await db.execute(
|
||||
# """
|
||||
# INSERT INTO diagonalley.orders (id, productid, wallet, product, quantity, shippingzone, address, email, invoiceid, paid, shipped)
|
||||
# INSERT INTO shop.orders (id, productid, wallet, product, quantity, shippingzone, address, email, invoiceid, paid, shipped)
|
||||
# VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
# """,
|
||||
# (
|
||||
|
@ -437,43 +437,43 @@ async def api_diagonalley_stall_checkshipped(
|
|||
##
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/markets")
|
||||
async def api_diagonalley_markets(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
# await get_diagonalley_market_stalls(market_id="FzpWnMyHQMcRppiGVua4eY")
|
||||
@shop_ext.get("/api/v1/markets")
|
||||
async def api_shop_markets(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
# await get_shop_market_stalls(market_id="FzpWnMyHQMcRppiGVua4eY")
|
||||
try:
|
||||
return [
|
||||
market.dict()
|
||||
for market in await get_diagonalley_markets(wallet.wallet.user)
|
||||
for market in await get_shop_markets(wallet.wallet.user)
|
||||
]
|
||||
except:
|
||||
return {"message": "We could not retrieve the markets."}
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/markets/{market_id}/stalls")
|
||||
async def api_diagonalley_market_stalls(market_id: str):
|
||||
stall_ids = await get_diagonalley_market_stalls(market_id)
|
||||
@shop_ext.get("/api/v1/markets/{market_id}/stalls")
|
||||
async def api_shop_market_stalls(market_id: str):
|
||||
stall_ids = await get_shop_market_stalls(market_id)
|
||||
return stall_ids
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/markets")
|
||||
@diagonalley_ext.put("/api/v1/markets/{market_id}")
|
||||
async def api_diagonalley_stall_create(
|
||||
@shop_ext.post("/api/v1/markets")
|
||||
@shop_ext.put("/api/v1/markets/{market_id}")
|
||||
async def api_shop_stall_create(
|
||||
data: CreateMarket,
|
||||
market_id: str = None,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
if market_id:
|
||||
market = await get_diagonalley_market(market_id)
|
||||
market = await get_shop_market(market_id)
|
||||
if not market:
|
||||
return {"message": "Market does not exist."}
|
||||
|
||||
if market.usr != wallet.wallet.user:
|
||||
return {"message": "Not your market."}
|
||||
|
||||
market = await update_diagonalley_market(market_id, **data.dict())
|
||||
market = await update_shop_market(market_id, **data.dict())
|
||||
else:
|
||||
market = await create_diagonalley_market(data=data)
|
||||
await create_diagonalley_market_stalls(market_id=market.id, data=data.stalls)
|
||||
market = await create_shop_market(data=data)
|
||||
await create_shop_market_stalls(market_id=market.id, data=data.stalls)
|
||||
|
||||
return market.dict()
|
||||
|
||||
|
@ -481,8 +481,8 @@ async def api_diagonalley_stall_create(
|
|||
## KEYS
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/keys")
|
||||
async def api_diagonalley_generate_keys():
|
||||
@shop_ext.get("/api/v1/keys")
|
||||
async def api_shop_generate_keys():
|
||||
private_key = PrivateKey()
|
||||
public_key = private_key.pubkey.serialize().hex()
|
||||
while not public_key.startswith("02"):
|
||||
|
@ -494,21 +494,21 @@ async def api_diagonalley_generate_keys():
|
|||
## MESSAGES/CHAT
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/chat/messages/merchant")
|
||||
@shop_ext.get("/api/v1/chat/messages/merchant")
|
||||
async def api_get_merchant_messages(
|
||||
orders: str = Query(...), wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
):
|
||||
|
||||
return [
|
||||
msg.dict() for msg in await get_diagonalley_chat_by_merchant(orders.split(","))
|
||||
msg.dict() for msg in await get_shop_chat_by_merchant(orders.split(","))
|
||||
]
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/chat/messages/{room_name}")
|
||||
@shop_ext.get("/api/v1/chat/messages/{room_name}")
|
||||
async def api_get_latest_chat_msg(room_name: str, all_messages: bool = Query(False)):
|
||||
if all_messages:
|
||||
messages = await get_diagonalley_chat_messages(room_name)
|
||||
messages = await get_shop_chat_messages(room_name)
|
||||
else:
|
||||
messages = await get_diagonalley_latest_chat_messages(room_name)
|
||||
messages = await get_shop_latest_chat_messages(room_name)
|
||||
|
||||
return messages
|
Loading…
Add table
Reference in a new issue