Renamed DA to shop
This commit is contained in:
parent
8fdebc2a98
commit
2a89743a3d
17 changed files with 354 additions and 354 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
<h1>Diagon Alley</h1>
|
<h1>Shop</h1>
|
||||||
<h2>A movable market stand</h2>
|
<h2>A movable market stand</h2>
|
||||||
Make a list of products to sell, point the list to an relay (or many), stack sats.
|
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">
|
<img src="https://i.imgur.com/P1tvBSG.png">
|
||||||
|
|
||||||
<h2>API endpoints</h2>
|
<h2>API endpoints</h2>
|
||||||
|
|
@ -7,20 +7,20 @@ from lnbits.db import Database
|
||||||
from lnbits.helpers import template_renderer
|
from lnbits.helpers import template_renderer
|
||||||
from lnbits.tasks import catch_everything_and_restart
|
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",
|
"path": "/shop/static",
|
||||||
"app": StaticFiles(directory="lnbits/extensions/diagonalley/static"),
|
"app": StaticFiles(directory="lnbits/extensions/shop/static"),
|
||||||
"name": "diagonalley_static",
|
"name": "shop_static",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
# if 'nostradmin' not in LNBITS_ADMIN_EXTENSIONS:
|
# if 'nostradmin' not in LNBITS_ADMIN_EXTENSIONS:
|
||||||
# @diagonalley_ext.get("/", response_class=HTMLResponse)
|
# @shop_ext.get("/", response_class=HTMLResponse)
|
||||||
# async def index(request: Request):
|
# async def index(request: Request):
|
||||||
# return template_renderer().TemplateResponse(
|
# return template_renderer().TemplateResponse(
|
||||||
# "error.html", {"request": request, "err": "Ask system admin to enable NostrAdmin!"}
|
# "error.html", {"request": request, "err": "Ask system admin to enable NostrAdmin!"}
|
||||||
|
|
@ -28,9 +28,9 @@ diagonalley_static_files = [
|
||||||
# else:
|
# else:
|
||||||
|
|
||||||
|
|
||||||
def diagonalley_renderer():
|
def shop_renderer():
|
||||||
return template_renderer(["lnbits/extensions/diagonalley/templates"])
|
return template_renderer(["lnbits/extensions/shop/templates"])
|
||||||
# return template_renderer(["lnbits/extensions/diagonalley/templates"])
|
# return template_renderer(["lnbits/extensions/shop/templates"])
|
||||||
|
|
||||||
|
|
||||||
from .tasks import wait_for_paid_invoices
|
from .tasks import wait_for_paid_invoices
|
||||||
|
|
@ -38,6 +38,6 @@ from .views import * # noqa
|
||||||
from .views_api import * # noqa
|
from .views_api import * # noqa
|
||||||
|
|
||||||
|
|
||||||
def diagonalley_start():
|
def shop_start():
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
||||||
|
|
@ -29,11 +29,11 @@ from .models import (
|
||||||
###Products
|
###Products
|
||||||
|
|
||||||
|
|
||||||
async def create_diagonalley_product(data: createProduct) -> Products:
|
async def create_shop_product(data: createProduct) -> Products:
|
||||||
product_id = urlsafe_short_hash()
|
product_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
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 (?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
|
@ -47,59 +47,59 @@ async def create_diagonalley_product(data: createProduct) -> Products:
|
||||||
data.quantity,
|
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"
|
assert product, "Newly created product couldn't be retrieved"
|
||||||
return product
|
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()])
|
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"UPDATE diagonalley.products SET {q} WHERE id = ?",
|
f"UPDATE shop.products SET {q} WHERE id = ?",
|
||||||
(*kwargs.values(), product_id),
|
(*kwargs.values(), product_id),
|
||||||
)
|
)
|
||||||
row = await db.fetchone(
|
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
|
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(
|
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
|
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):
|
if isinstance(stall_ids, str):
|
||||||
stall_ids = [stall_ids]
|
stall_ids = [stall_ids]
|
||||||
|
|
||||||
# with open_ext_db("diagonalley") as db:
|
# with open_ext_db("shop") as db:
|
||||||
q = ",".join(["?"] * len(stall_ids))
|
q = ",".join(["?"] * len(stall_ids))
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
f"""
|
f"""
|
||||||
SELECT * FROM diagonalley.products WHERE stall IN ({q})
|
SELECT * FROM shop.products WHERE stall IN ({q})
|
||||||
""",
|
""",
|
||||||
(*stall_ids,),
|
(*stall_ids,),
|
||||||
)
|
)
|
||||||
return [Products(**row) for row in rows]
|
return [Products(**row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
async def delete_diagonalley_product(product_id: str) -> None:
|
async def delete_shop_product(product_id: str) -> None:
|
||||||
await db.execute("DELETE FROM diagonalley.products WHERE id = ?", (product_id,))
|
await db.execute("DELETE FROM shop.products WHERE id = ?", (product_id,))
|
||||||
|
|
||||||
|
|
||||||
###zones
|
###zones
|
||||||
|
|
||||||
|
|
||||||
async def create_diagonalley_zone(user, data: createZones) -> Zones:
|
async def create_shop_zone(user, data: createZones) -> Zones:
|
||||||
zone_id = urlsafe_short_hash()
|
zone_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO diagonalley.zones (
|
INSERT INTO shop.zones (
|
||||||
id,
|
id,
|
||||||
"user",
|
"user",
|
||||||
cost,
|
cost,
|
||||||
|
|
@ -111,45 +111,45 @@ async def create_diagonalley_zone(user, data: createZones) -> Zones:
|
||||||
(zone_id, user, data.cost, data.countries.lower()),
|
(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"
|
assert zone, "Newly created zone couldn't be retrieved"
|
||||||
return zone
|
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()])
|
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"UPDATE diagonalley.zones SET {q} WHERE id = ?",
|
f"UPDATE shop.zones SET {q} WHERE id = ?",
|
||||||
(*kwargs.values(), zone_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
|
return Zones(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def get_diagonalley_zone(zone_id: str) -> Optional[Zones]:
|
async def get_shop_zone(zone_id: str) -> Optional[Zones]:
|
||||||
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
|
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(
|
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]
|
return [Zones(**row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
async def delete_diagonalley_zone(zone_id: str) -> None:
|
async def delete_shop_zone(zone_id: str) -> None:
|
||||||
await db.execute("DELETE FROM diagonalley.zones WHERE id = ?", (zone_id,))
|
await db.execute("DELETE FROM shop.zones WHERE id = ?", (zone_id,))
|
||||||
|
|
||||||
|
|
||||||
###Stalls
|
###Stalls
|
||||||
|
|
||||||
|
|
||||||
async def create_diagonalley_stall(data: createStalls) -> Stalls:
|
async def create_shop_stall(data: createStalls) -> Stalls:
|
||||||
stall_id = urlsafe_short_hash()
|
stall_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO diagonalley.stalls (
|
INSERT INTO shop.stalls (
|
||||||
id,
|
id,
|
||||||
wallet,
|
wallet,
|
||||||
name,
|
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"
|
assert stall, "Newly created stall couldn't be retrieved"
|
||||||
return stall
|
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()])
|
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"UPDATE diagonalley.stalls SET {q} WHERE id = ?",
|
f"UPDATE shop.stalls SET {q} WHERE id = ?",
|
||||||
(*kwargs.values(), stall_id),
|
(*kwargs.values(), stall_id),
|
||||||
)
|
)
|
||||||
row = await db.fetchone(
|
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
|
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(
|
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
|
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))
|
q = ",".join(["?"] * len(wallet_ids))
|
||||||
rows = await db.fetchall(
|
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]
|
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]]
|
stall_ids: Union[str, List[str]]
|
||||||
) -> List[Stalls]:
|
) -> List[Stalls]:
|
||||||
q = ",".join(["?"] * len(stall_ids))
|
q = ",".join(["?"] * len(stall_ids))
|
||||||
rows = await db.fetchall(
|
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]
|
return [Stalls(**row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
async def delete_diagonalley_stall(stall_id: str) -> None:
|
async def delete_shop_stall(stall_id: str) -> None:
|
||||||
await db.execute("DELETE FROM diagonalley.stalls WHERE id = ?", (stall_id,))
|
await db.execute("DELETE FROM shop.stalls WHERE id = ?", (stall_id,))
|
||||||
|
|
||||||
|
|
||||||
###Orders
|
###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"
|
returning = "" if db.type == SQLITE else "RETURNING ID"
|
||||||
method = db.execute if db.type == SQLITE else db.fetchone
|
method = db.execute if db.type == SQLITE else db.fetchone
|
||||||
|
|
||||||
result = await (method)(
|
result = await (method)(
|
||||||
f"""
|
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 (?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
{returning}
|
{returning}
|
||||||
""",
|
""",
|
||||||
|
|
@ -245,19 +245,19 @@ async def create_diagonalley_order(data: createOrder, invoiceid: str) -> Orders:
|
||||||
return result._result_proxy.lastrowid
|
return result._result_proxy.lastrowid
|
||||||
else:
|
else:
|
||||||
return result[0]
|
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"
|
# assert link, "Newly created link couldn't be retrieved"
|
||||||
# return link
|
# return link
|
||||||
|
|
||||||
|
|
||||||
async def create_diagonalley_order_details(
|
async def create_shop_order_details(
|
||||||
order_id: str, data: List[createOrderDetails]
|
order_id: str, data: List[createOrderDetails]
|
||||||
):
|
):
|
||||||
for item in data:
|
for item in data:
|
||||||
item_id = urlsafe_short_hash()
|
item_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
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 (?, ?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
|
@ -267,36 +267,36 @@ async def create_diagonalley_order_details(
|
||||||
item.quantity,
|
item.quantity,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
order_details = await get_diagonalley_order_details(order_id)
|
order_details = await get_shop_order_details(order_id)
|
||||||
return order_details
|
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(
|
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]
|
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(
|
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
|
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(
|
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
|
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(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE diagonalley.orders
|
UPDATE shop.orders
|
||||||
SET paid = true
|
SET paid = true
|
||||||
WHERE invoiceid = ?
|
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(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE diagonalley.orders
|
UPDATE shop.orders
|
||||||
SET pubkey = ?
|
SET pubkey = ?
|
||||||
WHERE invoiceid = ?
|
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(
|
q = "\n".join(
|
||||||
[f"""WHEN id='{p.product_id}' THEN quantity - {p.quantity}""" for p in products]
|
[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(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
UPDATE diagonalley.products
|
UPDATE shop.products
|
||||||
SET quantity=(CASE
|
SET quantity=(CASE
|
||||||
{q}
|
{q}
|
||||||
END)
|
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):
|
if isinstance(wallet_ids, str):
|
||||||
wallet_ids = [wallet_ids]
|
wallet_ids = [wallet_ids]
|
||||||
|
|
||||||
q = ",".join(["?"] * len(wallet_ids))
|
q = ",".join(["?"] * len(wallet_ids))
|
||||||
rows = await db.fetchall(
|
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]
|
return [Orders(**row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
async def delete_diagonalley_order(order_id: str) -> None:
|
async def delete_shop_order(order_id: str) -> None:
|
||||||
await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,))
|
await db.execute("DELETE FROM shop.orders WHERE id = ?", (order_id,))
|
||||||
|
|
||||||
|
|
||||||
### Market/Marketplace
|
### Market/Marketplace
|
||||||
|
|
||||||
|
|
||||||
async def get_diagonalley_markets(user: str) -> List[Market]:
|
async def get_shop_markets(user: str) -> List[Market]:
|
||||||
rows = await db.fetchall("SELECT * FROM diagonalley.markets WHERE usr = ?", (user,))
|
rows = await db.fetchall("SELECT * FROM shop.markets WHERE usr = ?", (user,))
|
||||||
return [Market(**row) for row in rows]
|
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(
|
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
|
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(
|
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]
|
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()
|
market_id = urlsafe_short_hash()
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO diagonalley.markets (id, usr, name)
|
INSERT INTO shop.markets (id, usr, name)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
|
@ -392,12 +392,12 @@ async def create_diagonalley_market(data: CreateMarket):
|
||||||
data.name,
|
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"
|
assert market, "Newly created market couldn't be retrieved"
|
||||||
return market
|
return market
|
||||||
|
|
||||||
|
|
||||||
async def create_diagonalley_market_stalls(
|
async def create_shop_market_stalls(
|
||||||
market_id: str, data: List[CreateMarketStalls]
|
market_id: str, data: List[CreateMarketStalls]
|
||||||
):
|
):
|
||||||
for stallid in data:
|
for stallid in data:
|
||||||
|
|
@ -405,7 +405,7 @@ async def create_diagonalley_market_stalls(
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO diagonalley.market_stalls (id, marketid, stallid)
|
INSERT INTO shop.market_stalls (id, marketid, stallid)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
|
@ -414,11 +414,11 @@ async def create_diagonalley_market_stalls(
|
||||||
stallid,
|
stallid,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
market_stalls = await get_diagonalley_market_stalls(market_id)
|
market_stalls = await get_shop_market_stalls(market_id)
|
||||||
return market_stalls
|
return market_stalls
|
||||||
|
|
||||||
|
|
||||||
async def update_diagonalley_market(market_id):
|
async def update_shop_market(market_id):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -428,7 +428,7 @@ async def update_diagonalley_market(market_id):
|
||||||
async def create_chat_message(data: CreateChatMessage):
|
async def create_chat_message(data: CreateChatMessage):
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO diagonalley.messages (msg, pubkey, id_conversation)
|
INSERT INTO shop.messages (msg, pubkey, id_conversation)
|
||||||
VALUES (?, ?, ?)
|
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(
|
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,),
|
(room_name,),
|
||||||
)
|
)
|
||||||
|
|
||||||
return [ChatMessage(**row) for row in rows]
|
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(
|
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,),
|
(room_name,),
|
||||||
)
|
)
|
||||||
|
|
||||||
return [ChatMessage(**row) for row in rows]
|
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))
|
q = ",".join(["?"] * len(ids))
|
||||||
rows = await db.fetchall(
|
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,),
|
(*ids,),
|
||||||
)
|
)
|
||||||
return [ChatMessage(**row) for row in rows]
|
return [ChatMessage(**row) for row in rows]
|
||||||
|
|
@ -4,7 +4,7 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE diagonalley.stalls (
|
CREATE TABLE shop.stalls (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
wallet TEXT NOT NULL,
|
wallet TEXT NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
|
|
@ -22,7 +22,7 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE diagonalley.products (
|
CREATE TABLE shop.products (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
stall TEXT NOT NULL REFERENCES {db.references_schema}stalls (id),
|
stall TEXT NOT NULL REFERENCES {db.references_schema}stalls (id),
|
||||||
product TEXT NOT NULL,
|
product TEXT NOT NULL,
|
||||||
|
|
@ -41,7 +41,7 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE diagonalley.zones (
|
CREATE TABLE shop.zones (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
"user" TEXT NOT NULL,
|
"user" TEXT NOT NULL,
|
||||||
cost TEXT NOT NULL,
|
cost TEXT NOT NULL,
|
||||||
|
|
@ -55,7 +55,7 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE diagonalley.orders (
|
CREATE TABLE shop.orders (
|
||||||
id {db.serial_primary_key},
|
id {db.serial_primary_key},
|
||||||
wallet TEXT NOT NULL,
|
wallet TEXT NOT NULL,
|
||||||
username TEXT,
|
username TEXT,
|
||||||
|
|
@ -79,7 +79,7 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE diagonalley.order_details (
|
CREATE TABLE shop.order_details (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
order_id INTEGER NOT NULL REFERENCES {db.references_schema}orders (id),
|
order_id INTEGER NOT NULL REFERENCES {db.references_schema}orders (id),
|
||||||
product_id TEXT NOT NULL REFERENCES {db.references_schema}products (id),
|
product_id TEXT NOT NULL REFERENCES {db.references_schema}products (id),
|
||||||
|
|
@ -93,7 +93,7 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE diagonalley.markets (
|
CREATE TABLE shop.markets (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
usr TEXT NOT NULL,
|
usr TEXT NOT NULL,
|
||||||
name TEXT
|
name TEXT
|
||||||
|
|
@ -106,7 +106,7 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE diagonalley.market_stalls (
|
CREATE TABLE shop.market_stalls (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
marketid TEXT NOT NULL REFERENCES {db.references_schema}markets (id),
|
marketid TEXT NOT NULL REFERENCES {db.references_schema}markets (id),
|
||||||
stallid TEXT NOT NULL REFERENCES {db.references_schema}stalls (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(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE diagonalley.messages (
|
CREATE TABLE shop.messages (
|
||||||
id {db.serial_primary_key},
|
id {db.serial_primary_key},
|
||||||
msg TEXT NOT NULL,
|
msg TEXT NOT NULL,
|
||||||
pubkey TEXT NOT NULL,
|
pubkey TEXT NOT NULL,
|
||||||
|
|
@ -138,8 +138,8 @@ async def m002_add_chat_messages(db):
|
||||||
Create indexes for message fetching
|
Create indexes for message fetching
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
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(
|
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 fastapi import WebSocket
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from lnbits.extensions.diagonalley.crud import create_chat_message
|
from lnbits.extensions.shop.crud import create_chat_message
|
||||||
from lnbits.extensions.diagonalley.models import CreateChatMessage
|
from lnbits.extensions.shop.models import CreateChatMessage
|
||||||
|
|
||||||
|
|
||||||
class Notifier:
|
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 lnbits.tasks import register_invoice_listener
|
||||||
|
|
||||||
from .crud import (
|
from .crud import (
|
||||||
get_diagonalley_order_details,
|
get_shop_order_details,
|
||||||
get_diagonalley_order_invoiceid,
|
get_shop_order_invoiceid,
|
||||||
set_diagonalley_order_paid,
|
set_shop_order_paid,
|
||||||
update_diagonalley_product_stock,
|
update_shop_product_stock,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -23,17 +23,17 @@ async def wait_for_paid_invoices():
|
||||||
|
|
||||||
|
|
||||||
async def on_invoice_paid(payment: Payment) -> None:
|
async def on_invoice_paid(payment: Payment) -> None:
|
||||||
if payment.extra.get("tag") != "diagonalley":
|
if payment.extra.get("tag") != "shop":
|
||||||
return
|
return
|
||||||
|
|
||||||
order = await get_diagonalley_order_invoiceid(payment.payment_hash)
|
order = await get_shop_order_invoiceid(payment.payment_hash)
|
||||||
if not order:
|
if not order:
|
||||||
logger.error("this should never happen", payment)
|
logger.error("this should never happen", payment)
|
||||||
return
|
return
|
||||||
|
|
||||||
# set order as paid
|
# 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
|
# deduct items sold from stock
|
||||||
details = await get_diagonalley_order_details(order.id)
|
details = await get_shop_order_details(order.id)
|
||||||
await update_diagonalley_product_stock(details)
|
await update_shop_product_stock(details)
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<h5 class="text-subtitle1 q-my-none">
|
<h5 class="text-subtitle1 q-my-none">
|
||||||
Diagon Alley: Decentralised Market-Stalls
|
Shop: Decentralised Market-Stalls
|
||||||
</h5>
|
</h5>
|
||||||
<p>Each Stall has its own keys!<br /></p>
|
<p>Each Stall has its own keys!<br /></p>
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
Ratings are managed by the relay. Your stall can be listed in multiple
|
Ratings are managed by the relay. Your stall can be listed in multiple
|
||||||
relays, even over TOR, if you wish to be anonymous.<br />
|
relays, even over TOR, if you wish to be anonymous.<br />
|
||||||
More information on the
|
More information on the
|
||||||
<a href="https://github.com/lnbits/Diagon-Alley">Diagon Alley Protocol</a
|
<a href="https://github.com/lnbits/Diagon-Alley">Shop Protocol</a
|
||||||
><br />
|
><br />
|
||||||
<small>
|
<small>
|
||||||
Created by, <a href="https://github.com/benarc">Ben Arc</a></small
|
Created by, <a href="https://github.com/benarc">Ben Arc</a></small
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code
|
<code
|
||||||
><span class="text-light-blue">GET</span>
|
><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">Body (application/json)</h5>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">
|
<h5 class="text-caption q-mt-sm q-mb-none">
|
||||||
|
|
@ -76,7 +76,7 @@
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code
|
<code
|
||||||
><span class="text-light-green">POST</span>
|
><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>
|
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
||||||
<code
|
<code
|
||||||
|
|
@ -112,7 +112,7 @@
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code
|
<code
|
||||||
><span class="text-light-blue">GET</span>
|
><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">Headers</h5>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">
|
<h5 class="text-caption q-mt-sm q-mb-none">
|
||||||
|
|
@ -398,9 +398,9 @@
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-separator inset></q-separator>
|
<q-separator inset></q-separator>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<div class="text-h6">Diagon Alley</div>
|
<div class="text-h6">Shop</div>
|
||||||
<div class="text-subtitle2">
|
<div class="text-subtitle2">
|
||||||
Step inside the Leaky Cauldron and enter the Diagon Alley. Make this
|
Step inside the Leaky Cauldron and enter the Shop. Make this
|
||||||
market available on Nostr!
|
market available on Nostr!
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
|
@ -412,7 +412,7 @@
|
||||||
checked-icon="check"
|
checked-icon="check"
|
||||||
color="green"
|
color="green"
|
||||||
unchecked-icon="clear"
|
unchecked-icon="clear"
|
||||||
label='"Diagon Alley" mode (Nostr)'
|
label='"Shop" mode (Nostr)'
|
||||||
@input="toggleDA"
|
@input="toggleDA"
|
||||||
>
|
>
|
||||||
<q-tooltip>Coming soon...</q-tooltip></q-toggle
|
<q-tooltip>Coming soon...</q-tooltip></q-toggle
|
||||||
|
|
@ -703,7 +703,7 @@
|
||||||
icon="storefront"
|
icon="storefront"
|
||||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||||
type="a"
|
type="a"
|
||||||
:href="'/diagonalley/stalls/' + props.row.id"
|
:href="'/shop/stalls/' + props.row.id"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
<q-tooltip> Stall simple UI shopping cart </q-tooltip>
|
<q-tooltip> Stall simple UI shopping cart </q-tooltip>
|
||||||
|
|
@ -777,7 +777,7 @@
|
||||||
icon="storefront"
|
icon="storefront"
|
||||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||||
type="a"
|
type="a"
|
||||||
:href="'/diagonalley/market/' + props.row.id"
|
:href="'/shop/market/' + props.row.id"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
<q-tooltip> Link to pass to stall relay </q-tooltip>
|
<q-tooltip> Link to pass to stall relay </q-tooltip>
|
||||||
|
|
@ -921,12 +921,12 @@
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<h6 class="text-subtitle1 q-my-none">
|
<h6 class="text-subtitle1 q-my-none">
|
||||||
LNbits Diagon Alley Extension, powered by Nostr
|
LNbits Shop Extension, powered by Nostr
|
||||||
</h6>
|
</h6>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section class="q-pa-none">
|
<q-card-section class="q-pa-none">
|
||||||
<q-separator></q-separator>
|
<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-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
<!-- CHAT BOX -->
|
<!-- CHAT BOX -->
|
||||||
|
|
@ -1062,7 +1062,7 @@
|
||||||
</div>
|
</div>
|
||||||
<q-dialog v-model="onboarding.show">
|
<q-dialog v-model="onboarding.show">
|
||||||
<q-card class="q-pa-lg">
|
<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-stepper v-model="step" color="primary" vertical animated>
|
||||||
<q-step
|
<q-step
|
||||||
:name="1"
|
:name="1"
|
||||||
|
|
@ -1155,7 +1155,7 @@
|
||||||
obj._data = _.clone(obj)
|
obj._data = _.clone(obj)
|
||||||
obj.stores = []
|
obj.stores = []
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request('GET', `/diagonalley/api/v1/markets/${obj.id}/stalls`, null)
|
.request('GET', `/shop/api/v1/markets/${obj.id}/stalls`, null)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
obj.stores = response.data.map(s => s.name).toString()
|
obj.stores = response.data.map(s => s.name).toString()
|
||||||
|
|
@ -1503,7 +1503,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/diagonalley/api/v1/keys',
|
'/shop/api/v1/keys',
|
||||||
this.g.user.wallets[0].adminkey
|
this.g.user.wallets[0].adminkey
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
@ -1512,7 +1512,7 @@
|
||||||
this.stallDialog.data.publickey = this.keys.pubkey
|
this.stallDialog.data.publickey = this.keys.pubkey
|
||||||
this.stallDialog.data.privatekey = this.keys.privkey
|
this.stallDialog.data.privatekey = this.keys.privkey
|
||||||
this.$q.localStorage.set(
|
this.$q.localStorage.set(
|
||||||
`lnbits.diagonalley.${this.g.user.id}`,
|
`lnbits.shop.${this.g.user.id}`,
|
||||||
this.keys
|
this.keys
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1523,7 +1523,7 @@
|
||||||
},
|
},
|
||||||
restoreKeys() {
|
restoreKeys() {
|
||||||
let keys = this.$q.localStorage.getItem(
|
let keys = this.$q.localStorage.getItem(
|
||||||
`lnbits.diagonalley.${this.g.user.id}`
|
`lnbits.shop.${this.g.user.id}`
|
||||||
)
|
)
|
||||||
if (keys) {
|
if (keys) {
|
||||||
this.keys = keys
|
this.keys = keys
|
||||||
|
|
@ -1580,7 +1580,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/diagonalley/api/v1/stalls?all_wallets=true',
|
'/shop/api/v1/stalls?all_wallets=true',
|
||||||
self.g.user.wallets[0].adminkey
|
self.g.user.wallets[0].adminkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -1636,7 +1636,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/diagonalley/api/v1/stalls/' + data.id,
|
'/shop/api/v1/stalls/' + data.id,
|
||||||
_.findWhere(self.g.user.wallets, {
|
_.findWhere(self.g.user.wallets, {
|
||||||
id: self.stallDialog.data.wallet
|
id: self.stallDialog.data.wallet
|
||||||
}).inkey,
|
}).inkey,
|
||||||
|
|
@ -1658,7 +1658,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/diagonalley/api/v1/stalls',
|
'/shop/api/v1/stalls',
|
||||||
_.findWhere(self.g.user.wallets, {
|
_.findWhere(self.g.user.wallets, {
|
||||||
id: self.stallDialog.data.wallet
|
id: self.stallDialog.data.wallet
|
||||||
}).inkey,
|
}).inkey,
|
||||||
|
|
@ -1685,7 +1685,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/diagonalley/api/v1/stalls/' + stallId,
|
'/shop/api/v1/stalls/' + stallId,
|
||||||
_.findWhere(self.g.user.wallets, {id: stall.wallet}).adminkey
|
_.findWhere(self.g.user.wallets, {id: stall.wallet}).adminkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -1710,7 +1710,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/diagonalley/api/v1/products?all_stalls=true',
|
'/shop/api/v1/products?all_stalls=true',
|
||||||
self.g.user.wallets[0].inkey
|
self.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -1783,7 +1783,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/diagonalley/api/v1/products/' + data.id,
|
'/shop/api/v1/products/' + data.id,
|
||||||
_.findWhere(self.g.user.wallets, {
|
_.findWhere(self.g.user.wallets, {
|
||||||
id: wallet
|
id: wallet
|
||||||
}).inkey,
|
}).inkey,
|
||||||
|
|
@ -1809,7 +1809,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/diagonalley/api/v1/products',
|
'/shop/api/v1/products',
|
||||||
_.findWhere(self.g.user.wallets, {id: walletId}).inkey,
|
_.findWhere(self.g.user.wallets, {id: walletId}).inkey,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
@ -1831,7 +1831,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/diagonalley/api/v1/products/' + productId,
|
'/shop/api/v1/products/' + productId,
|
||||||
_.findWhere(this.g.user.wallets, {id: walletId}).adminkey
|
_.findWhere(this.g.user.wallets, {id: walletId}).adminkey
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
@ -1856,7 +1856,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/diagonalley/api/v1/zones',
|
'/shop/api/v1/zones',
|
||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -1896,7 +1896,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/diagonalley/api/v1/zones/' + data.id,
|
'/shop/api/v1/zones/' + data.id,
|
||||||
self.g.user.wallets[0].adminkey,
|
self.g.user.wallets[0].adminkey,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
@ -1918,7 +1918,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/diagonalley/api/v1/zones',
|
'/shop/api/v1/zones',
|
||||||
self.g.user.wallets[0].inkey,
|
self.g.user.wallets[0].inkey,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
@ -1942,7 +1942,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/diagonalley/api/v1/zones/' + zoneId,
|
'/shop/api/v1/zones/' + zoneId,
|
||||||
self.g.user.wallets[0].adminkey
|
self.g.user.wallets[0].adminkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -1965,7 +1965,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/diagonalley/api/v1/markets',
|
'/shop/api/v1/markets',
|
||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
@ -2003,7 +2003,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/diagonalley/api/v1/shops' + data.id,
|
'/shop/api/v1/shops' + data.id,
|
||||||
_.findWhere(self.g.user.wallets, {
|
_.findWhere(self.g.user.wallets, {
|
||||||
id: self.marketDialog.data.wallet
|
id: self.marketDialog.data.wallet
|
||||||
}).inkey,
|
}).inkey,
|
||||||
|
|
@ -2026,7 +2026,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/diagonalley/api/v1/markets',
|
'/shop/api/v1/markets',
|
||||||
this.g.user.wallets[0].inkey,
|
this.g.user.wallets[0].inkey,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
@ -2050,7 +2050,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/diagonalley/api/v1/shops/' + shopId,
|
'/shop/api/v1/shops/' + shopId,
|
||||||
_.findWhere(self.g.user.wallets, {id: shop.wallet}).inkey
|
_.findWhere(self.g.user.wallets, {id: shop.wallet}).inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -2075,7 +2075,7 @@
|
||||||
await LNbits.api
|
await LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/diagonalley/api/v1/orders?all_wallets=true',
|
'/shop/api/v1/orders?all_wallets=true',
|
||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -2099,7 +2099,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/diagonalley/api/v1/orders',
|
'/shop/api/v1/orders',
|
||||||
_.findWhere(self.g.user.wallets, {id: self.orderDialog.data.wallet})
|
_.findWhere(self.g.user.wallets, {id: self.orderDialog.data.wallet})
|
||||||
.inkey,
|
.inkey,
|
||||||
data
|
data
|
||||||
|
|
@ -2123,7 +2123,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/diagonalley/api/v1/orders/' + orderId,
|
'/shop/api/v1/orders/' + orderId,
|
||||||
_.findWhere(self.g.user.wallets, {id: order.wallet}).adminkey
|
_.findWhere(self.g.user.wallets, {id: order.wallet}).adminkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -2140,7 +2140,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/diagonalley/api/v1/orders/shipped/' + order_id,
|
'/shop/api/v1/orders/shipped/' + order_id,
|
||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
@ -2161,7 +2161,7 @@
|
||||||
await LNbits.api
|
await LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
`/diagonalley/api/v1/chat/messages/merchant?orders=${this.orders
|
`/shop/api/v1/chat/messages/merchant?orders=${this.orders
|
||||||
.map(o => o.invoiceid)
|
.map(o => o.invoiceid)
|
||||||
.toString()}`,
|
.toString()}`,
|
||||||
this.g.user.wallets[0].adminkey
|
this.g.user.wallets[0].adminkey
|
||||||
|
|
@ -2176,7 +2176,7 @@
|
||||||
},
|
},
|
||||||
updateLastSeenMsg(id) {
|
updateLastSeenMsg(id) {
|
||||||
let data = this.$q.localStorage.getItem(
|
let data = this.$q.localStorage.getItem(
|
||||||
`lnbits.diagonalley.${this.g.user.id}`
|
`lnbits.shop.${this.g.user.id}`
|
||||||
)
|
)
|
||||||
let chat = {
|
let chat = {
|
||||||
...data.chat,
|
...data.chat,
|
||||||
|
|
@ -2186,7 +2186,7 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.$q.localStorage.set(`lnbits.diagonalley.${this.g.user.id}`, {
|
this.$q.localStorage.set(`lnbits.shop.${this.g.user.id}`, {
|
||||||
...data,
|
...data,
|
||||||
chat
|
chat
|
||||||
})
|
})
|
||||||
|
|
@ -2194,7 +2194,7 @@
|
||||||
},
|
},
|
||||||
checkUnreadMessages() {
|
checkUnreadMessages() {
|
||||||
let lastMsgs = this.$q.localStorage.getItem(
|
let lastMsgs = this.$q.localStorage.getItem(
|
||||||
`lnbits.diagonalley.${this.g.user.id}`
|
`lnbits.shop.${this.g.user.id}`
|
||||||
).chat
|
).chat
|
||||||
for (let key in this.messages) {
|
for (let key in this.messages) {
|
||||||
let idx = this.orders.findIndex(f => f.invoiceid == key)
|
let idx = this.orders.findIndex(f => f.invoiceid == key)
|
||||||
|
|
@ -2253,14 +2253,14 @@
|
||||||
ws_scheme = 'ws://'
|
ws_scheme = 'ws://'
|
||||||
}
|
}
|
||||||
ws = new WebSocket(
|
ws = new WebSocket(
|
||||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||||
)
|
)
|
||||||
|
|
||||||
function checkWebSocket(event) {
|
function checkWebSocket(event) {
|
||||||
if (ws.readyState === WebSocket.CLOSED) {
|
if (ws.readyState === WebSocket.CLOSED) {
|
||||||
console.log('WebSocket CLOSED: Reopening')
|
console.log('WebSocket CLOSED: Reopening')
|
||||||
ws = new WebSocket(
|
ws = new WebSocket(
|
||||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2293,7 +2293,7 @@
|
||||||
this.getMarkets()
|
this.getMarkets()
|
||||||
await this.getAllMessages()
|
await this.getAllMessages()
|
||||||
let keys = this.$q.localStorage.getItem(
|
let keys = this.$q.localStorage.getItem(
|
||||||
`lnbits.diagonalley.${this.g.user.id}`
|
`lnbits.shop.${this.g.user.id}`
|
||||||
)
|
)
|
||||||
if (keys) {
|
if (keys) {
|
||||||
this.keys = keys
|
this.keys = keys
|
||||||
|
|
@ -76,7 +76,7 @@
|
||||||
<q-card class="card--product">
|
<q-card class="card--product">
|
||||||
{% raw %}
|
{% raw %}
|
||||||
<q-img
|
<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"
|
alt="Product Image"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
spinner-color="white"
|
spinner-color="white"
|
||||||
|
|
@ -357,7 +357,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request('POST', '/diagonalley/api/v1/orders', null, data)
|
.request('POST', '/shop/api/v1/orders', null, data)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.checkoutDialog = {show: false, data: {}}
|
this.checkoutDialog = {show: false, data: {}}
|
||||||
|
|
||||||
|
|
@ -378,7 +378,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
`/diagonalley/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
`/shop/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
||||||
)
|
)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.data.paid) {
|
if (res.data.paid) {
|
||||||
|
|
@ -320,8 +320,8 @@
|
||||||
},
|
},
|
||||||
restoreKeys() {
|
restoreKeys() {
|
||||||
this.user.keys = this.keysDialog.data
|
this.user.keys = this.keysDialog.data
|
||||||
let data = this.$q.localStorage.getItem(`lnbits.diagonalley.data`)
|
let data = this.$q.localStorage.getItem(`lnbits.shop.data`)
|
||||||
this.$q.localStorage.set(`lnbits.diagonalley.data`, {
|
this.$q.localStorage.set(`lnbits.shop.data`, {
|
||||||
...data,
|
...data,
|
||||||
keys: this.user.keys
|
keys: this.user.keys
|
||||||
})
|
})
|
||||||
|
|
@ -332,7 +332,7 @@
|
||||||
LNbits.utils
|
LNbits.utils
|
||||||
.confirmDialog('Are you sure you want to delete your stored data?')
|
.confirmDialog('Are you sure you want to delete your stored data?')
|
||||||
.onOk(() => {
|
.onOk(() => {
|
||||||
this.$q.localStorage.remove('lnbits.diagonalley.data')
|
this.$q.localStorage.remove('lnbits.shop.data')
|
||||||
this.user = null
|
this.user = null
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
@ -342,7 +342,7 @@
|
||||||
return
|
return
|
||||||
|
|
||||||
return await LNbits.api
|
return await LNbits.api
|
||||||
.request('GET', `/diagonalley/api/v1/keys`, null)
|
.request('GET', `/shop/api/v1/keys`, null)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
let data = {
|
let data = {
|
||||||
|
|
@ -363,7 +363,7 @@
|
||||||
await LNbits.api
|
await LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
`/diagonalley/api/v1/chat/messages/${room_name}${
|
`/shop/api/v1/chat/messages/${room_name}${
|
||||||
all ? '?all_messages=true' : ''
|
all ? '?all_messages=true' : ''
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
|
|
@ -397,14 +397,14 @@
|
||||||
ws_scheme = 'ws://'
|
ws_scheme = 'ws://'
|
||||||
}
|
}
|
||||||
ws = new WebSocket(
|
ws = new WebSocket(
|
||||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||||
)
|
)
|
||||||
|
|
||||||
function checkWebSocket(event) {
|
function checkWebSocket(event) {
|
||||||
if (ws.readyState === WebSocket.CLOSED) {
|
if (ws.readyState === WebSocket.CLOSED) {
|
||||||
console.log('WebSocket CLOSED: Reopening')
|
console.log('WebSocket CLOSED: Reopening')
|
||||||
ws = new WebSocket(
|
ws = new WebSocket(
|
||||||
ws_scheme + location.host + '/diagonalley/ws/' + room_name
|
ws_scheme + location.host + '/shop/ws/' + room_name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -447,7 +447,7 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
let data =
|
let data =
|
||||||
this.$q.localStorage.getItem(`lnbits.diagonalley.data`) || false
|
this.$q.localStorage.getItem(`lnbits.shop.data`) || false
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
this.user = data
|
this.user = data
|
||||||
|
|
@ -468,7 +468,7 @@
|
||||||
|
|
||||||
await this.getMessages(order_id)
|
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)
|
this.startChat(order_id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -76,7 +76,7 @@
|
||||||
<q-card class="card--product">
|
<q-card class="card--product">
|
||||||
{% raw %}
|
{% raw %}
|
||||||
<q-img
|
<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"
|
alt="Product Image"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
spinner-color="white"
|
spinner-color="white"
|
||||||
|
|
@ -359,7 +359,7 @@
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getPubkey() {
|
getPubkey() {
|
||||||
let data = this.$q.localStorage.getItem(`lnbits.diagonalley.data`)
|
let data = this.$q.localStorage.getItem(`lnbits.shop.data`)
|
||||||
if (data && data.keys.publickey) {
|
if (data && data.keys.publickey) {
|
||||||
this.checkoutDialog.data.pubkey = data.keys.publickey
|
this.checkoutDialog.data.pubkey = data.keys.publickey
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -381,7 +381,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request('POST', '/diagonalley/api/v1/orders', null, data)
|
.request('POST', '/shop/api/v1/orders', null, data)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.checkoutDialog = {show: false, data: {}}
|
this.checkoutDialog = {show: false, data: {}}
|
||||||
|
|
||||||
|
|
@ -402,7 +402,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
`/diagonalley/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
`/shop/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
||||||
)
|
)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.data.paid) {
|
if (res.data.paid) {
|
||||||
|
|
@ -416,7 +416,7 @@
|
||||||
{
|
{
|
||||||
label: 'See Order',
|
label: 'See Order',
|
||||||
handler: () => {
|
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}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -425,7 +425,7 @@
|
||||||
this.resetCart()
|
this.resetCart()
|
||||||
this.closeQrCodeDialog()
|
this.closeQrCodeDialog()
|
||||||
setTimeout(() => {
|
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)
|
}, 5000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -11,40 +11,40 @@ from starlette.responses import HTMLResponse
|
||||||
|
|
||||||
from lnbits.core.models import User
|
from lnbits.core.models import User
|
||||||
from lnbits.decorators import check_user_exists # type: ignore
|
from lnbits.decorators import check_user_exists # type: ignore
|
||||||
from lnbits.extensions.diagonalley import diagonalley_ext, diagonalley_renderer
|
from lnbits.extensions.shop import shop_ext, shop_renderer
|
||||||
from lnbits.extensions.diagonalley.models import CreateChatMessage
|
from lnbits.extensions.shop.models import CreateChatMessage
|
||||||
from lnbits.extensions.diagonalley.notifier import Notifier
|
from lnbits.extensions.shop.notifier import Notifier
|
||||||
|
|
||||||
from .crud import (
|
from .crud import (
|
||||||
create_chat_message,
|
create_chat_message,
|
||||||
get_diagonalley_market,
|
get_shop_market,
|
||||||
get_diagonalley_market_stalls,
|
get_shop_market_stalls,
|
||||||
get_diagonalley_order_details,
|
get_shop_order_details,
|
||||||
get_diagonalley_order_invoiceid,
|
get_shop_order_invoiceid,
|
||||||
get_diagonalley_products,
|
get_shop_products,
|
||||||
get_diagonalley_stall,
|
get_shop_stall,
|
||||||
get_diagonalley_zone,
|
get_shop_zone,
|
||||||
get_diagonalley_zones,
|
get_shop_zones,
|
||||||
update_diagonalley_product_stock,
|
update_shop_product_stock,
|
||||||
)
|
)
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
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)):
|
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||||
return diagonalley_renderer().TemplateResponse(
|
return shop_renderer().TemplateResponse(
|
||||||
"diagonalley/index.html", {"request": request, "user": user.dict()}
|
"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):
|
async def display(request: Request, stall_id):
|
||||||
stall = await get_diagonalley_stall(stall_id)
|
stall = await get_shop_stall(stall_id)
|
||||||
products = await get_diagonalley_products(stall_id)
|
products = await get_shop_products(stall_id)
|
||||||
zones = []
|
zones = []
|
||||||
for id in stall.shippingzones.split(","):
|
for id in stall.shippingzones.split(","):
|
||||||
z = await get_diagonalley_zone(id)
|
z = await get_shop_zone(id)
|
||||||
z = z.dict()
|
z = z.dict()
|
||||||
zones.append({"label": z["countries"], "cost": z["cost"], "value": z["id"]})
|
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"]
|
del stall["privatekey"]
|
||||||
stall["zones"] = zones
|
stall["zones"] = zones
|
||||||
|
|
||||||
return diagonalley_renderer().TemplateResponse(
|
return shop_renderer().TemplateResponse(
|
||||||
"diagonalley/stall.html",
|
"shop/stall.html",
|
||||||
{
|
{
|
||||||
"request": request,
|
"request": request,
|
||||||
"stall": stall,
|
"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):
|
async def display(request: Request, market_id):
|
||||||
market = await get_diagonalley_market(market_id)
|
market = await get_shop_market(market_id)
|
||||||
|
|
||||||
if not market:
|
if not market:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="Marketplace doesn't exist."
|
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]
|
stalls_ids = [stall.id for stall in stalls]
|
||||||
products = [
|
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(
|
return shop_renderer().TemplateResponse(
|
||||||
"diagonalley/market.html",
|
"shop/market.html",
|
||||||
{
|
{
|
||||||
"request": request,
|
"request": request,
|
||||||
"market": market,
|
"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(
|
async def chat_page(
|
||||||
request: Request,
|
request: Request,
|
||||||
merch: str = Query(...),
|
merch: str = Query(...),
|
||||||
invoice_id: str = Query(...),
|
invoice_id: str = Query(...),
|
||||||
keys: str = Query(None),
|
keys: str = Query(None),
|
||||||
):
|
):
|
||||||
stall = await get_diagonalley_stall(merch)
|
stall = await get_shop_stall(merch)
|
||||||
order = await get_diagonalley_order_invoiceid(invoice_id)
|
order = await get_shop_order_invoiceid(invoice_id)
|
||||||
_order = await get_diagonalley_order_details(order.id)
|
_order = await get_shop_order_details(order.id)
|
||||||
products = await get_diagonalley_products(stall.id)
|
products = await get_shop_products(stall.id)
|
||||||
|
|
||||||
return diagonalley_renderer().TemplateResponse(
|
return shop_renderer().TemplateResponse(
|
||||||
"diagonalley/order.html",
|
"shop/order.html",
|
||||||
{
|
{
|
||||||
"request": request,
|
"request": request,
|
||||||
"stall": {
|
"stall": {
|
||||||
|
|
@ -155,7 +155,7 @@ notifier = Notifier()
|
||||||
# manager = ConnectionManager()
|
# manager = ConnectionManager()
|
||||||
|
|
||||||
|
|
||||||
# @diagonalley_ext.websocket("/ws/{room_name}")
|
# @shop_ext.websocket("/ws/{room_name}")
|
||||||
# async def websocket_endpoint(websocket: WebSocket, room_name: str):
|
# async def websocket_endpoint(websocket: WebSocket, room_name: str):
|
||||||
# await manager.connect(websocket, room_name)
|
# await manager.connect(websocket, room_name)
|
||||||
# try:
|
# try:
|
||||||
|
|
@ -165,7 +165,7 @@ notifier = Notifier()
|
||||||
# manager.disconnect(websocket)
|
# manager.disconnect(websocket)
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.websocket("/ws/{room_name}")
|
@shop_ext.websocket("/ws/{room_name}")
|
||||||
async def websocket_endpoint(
|
async def websocket_endpoint(
|
||||||
websocket: WebSocket, room_name: str, background_tasks: BackgroundTasks
|
websocket: WebSocket, room_name: str, background_tasks: BackgroundTasks
|
||||||
):
|
):
|
||||||
|
|
@ -21,41 +21,41 @@ from lnbits.decorators import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from ...helpers import urlsafe_short_hash
|
from ...helpers import urlsafe_short_hash
|
||||||
from . import db, diagonalley_ext
|
from . import db, shop_ext
|
||||||
from .crud import (
|
from .crud import (
|
||||||
create_diagonalley_market,
|
create_shop_market,
|
||||||
create_diagonalley_market_stalls,
|
create_shop_market_stalls,
|
||||||
create_diagonalley_order,
|
create_shop_order,
|
||||||
create_diagonalley_order_details,
|
create_shop_order_details,
|
||||||
create_diagonalley_product,
|
create_shop_product,
|
||||||
create_diagonalley_stall,
|
create_shop_stall,
|
||||||
create_diagonalley_zone,
|
create_shop_zone,
|
||||||
delete_diagonalley_order,
|
delete_shop_order,
|
||||||
delete_diagonalley_product,
|
delete_shop_product,
|
||||||
delete_diagonalley_stall,
|
delete_shop_stall,
|
||||||
delete_diagonalley_zone,
|
delete_shop_zone,
|
||||||
get_diagonalley_chat_by_merchant,
|
get_shop_chat_by_merchant,
|
||||||
get_diagonalley_chat_messages,
|
get_shop_chat_messages,
|
||||||
get_diagonalley_latest_chat_messages,
|
get_shop_latest_chat_messages,
|
||||||
get_diagonalley_market,
|
get_shop_market,
|
||||||
get_diagonalley_market_stalls,
|
get_shop_market_stalls,
|
||||||
get_diagonalley_markets,
|
get_shop_markets,
|
||||||
get_diagonalley_order,
|
get_shop_order,
|
||||||
get_diagonalley_order_details,
|
get_shop_order_details,
|
||||||
get_diagonalley_order_invoiceid,
|
get_shop_order_invoiceid,
|
||||||
get_diagonalley_orders,
|
get_shop_orders,
|
||||||
get_diagonalley_product,
|
get_shop_product,
|
||||||
get_diagonalley_products,
|
get_shop_products,
|
||||||
get_diagonalley_stall,
|
get_shop_stall,
|
||||||
get_diagonalley_stalls,
|
get_shop_stalls,
|
||||||
get_diagonalley_stalls_by_ids,
|
get_shop_stalls_by_ids,
|
||||||
get_diagonalley_zone,
|
get_shop_zone,
|
||||||
get_diagonalley_zones,
|
get_shop_zones,
|
||||||
set_diagonalley_order_pubkey,
|
set_shop_order_pubkey,
|
||||||
update_diagonalley_market,
|
update_shop_market,
|
||||||
update_diagonalley_product,
|
update_shop_product,
|
||||||
update_diagonalley_stall,
|
update_shop_stall,
|
||||||
update_diagonalley_zone,
|
update_shop_zone,
|
||||||
)
|
)
|
||||||
from .models import (
|
from .models import (
|
||||||
CreateMarket,
|
CreateMarket,
|
||||||
|
|
@ -73,8 +73,8 @@ from .models import (
|
||||||
|
|
||||||
|
|
||||||
### Products
|
### Products
|
||||||
@diagonalley_ext.get("/api/v1/products")
|
@shop_ext.get("/api/v1/products")
|
||||||
async def api_diagonalley_products(
|
async def api_shop_products(
|
||||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||||
all_stalls: bool = Query(False),
|
all_stalls: bool = Query(False),
|
||||||
):
|
):
|
||||||
|
|
@ -83,90 +83,90 @@ async def api_diagonalley_products(
|
||||||
if all_stalls:
|
if all_stalls:
|
||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
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:
|
if not stalls:
|
||||||
return
|
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")
|
@shop_ext.post("/api/v1/products")
|
||||||
@diagonalley_ext.put("/api/v1/products/{product_id}")
|
@shop_ext.put("/api/v1/products/{product_id}")
|
||||||
async def api_diagonalley_product_create(
|
async def api_shop_product_create(
|
||||||
data: createProduct, product_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
|
data: createProduct, product_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
|
|
||||||
if product_id:
|
if product_id:
|
||||||
product = await get_diagonalley_product(product_id)
|
product = await get_shop_product(product_id)
|
||||||
if not product:
|
if not product:
|
||||||
return {"message": "Withdraw product does not exist."}
|
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:
|
if stall.wallet != wallet.wallet.id:
|
||||||
return {"message": "Not your withdraw product."}
|
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:
|
else:
|
||||||
product = await create_diagonalley_product(data=data)
|
product = await create_shop_product(data=data)
|
||||||
|
|
||||||
return product.dict()
|
return product.dict()
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.delete("/api/v1/products/{product_id}")
|
@shop_ext.delete("/api/v1/products/{product_id}")
|
||||||
async def api_diagonalley_products_delete(
|
async def api_shop_products_delete(
|
||||||
product_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
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:
|
if not product:
|
||||||
return {"message": "Product does not exist."}
|
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:
|
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)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
# # # Shippingzones
|
# # # Shippingzones
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/zones")
|
@shop_ext.get("/api/v1/zones")
|
||||||
async def api_diagonalley_zones(wallet: WalletTypeInfo = Depends(get_key_type)):
|
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")
|
@shop_ext.post("/api/v1/zones")
|
||||||
async def api_diagonalley_zone_create(
|
async def api_shop_zone_create(
|
||||||
data: createZones, wallet: WalletTypeInfo = Depends(get_key_type)
|
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()
|
return zone.dict()
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.post("/api/v1/zones/{zone_id}")
|
@shop_ext.post("/api/v1/zones/{zone_id}")
|
||||||
async def api_diagonalley_zone_update(
|
async def api_shop_zone_update(
|
||||||
data: createZones,
|
data: createZones,
|
||||||
zone_id: str,
|
zone_id: str,
|
||||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||||
):
|
):
|
||||||
zone = await get_diagonalley_zone(zone_id)
|
zone = await get_shop_zone(zone_id)
|
||||||
if not zone:
|
if not zone:
|
||||||
return {"message": "Zone does not exist."}
|
return {"message": "Zone does not exist."}
|
||||||
if zone.user != wallet.wallet.user:
|
if zone.user != wallet.wallet.user:
|
||||||
return {"message": "Not your record."}
|
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
|
return zone
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.delete("/api/v1/zones/{zone_id}")
|
@shop_ext.delete("/api/v1/zones/{zone_id}")
|
||||||
async def api_diagonalley_zone_delete(
|
async def api_shop_zone_delete(
|
||||||
zone_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
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:
|
if not zone:
|
||||||
return {"message": "zone does not exist."}
|
return {"message": "zone does not exist."}
|
||||||
|
|
@ -174,15 +174,15 @@ async def api_diagonalley_zone_delete(
|
||||||
if zone.user != wallet.wallet.user:
|
if zone.user != wallet.wallet.user:
|
||||||
return {"message": "Not your zone."}
|
return {"message": "Not your zone."}
|
||||||
|
|
||||||
await delete_diagonalley_zone(zone_id)
|
await delete_shop_zone(zone_id)
|
||||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
# # # Stalls
|
# # # Stalls
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/stalls")
|
@shop_ext.get("/api/v1/stalls")
|
||||||
async def api_diagonalley_stalls(
|
async def api_shop_stalls(
|
||||||
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
||||||
):
|
):
|
||||||
wallet_ids = [wallet.wallet.id]
|
wallet_ids = [wallet.wallet.id]
|
||||||
|
|
@ -190,37 +190,37 @@ async def api_diagonalley_stalls(
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
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")
|
@shop_ext.post("/api/v1/stalls")
|
||||||
@diagonalley_ext.put("/api/v1/stalls/{stall_id}")
|
@shop_ext.put("/api/v1/stalls/{stall_id}")
|
||||||
async def api_diagonalley_stall_create(
|
async def api_shop_stall_create(
|
||||||
data: createStalls,
|
data: createStalls,
|
||||||
stall_id: str = None,
|
stall_id: str = None,
|
||||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||||
):
|
):
|
||||||
|
|
||||||
if stall_id:
|
if stall_id:
|
||||||
stall = await get_diagonalley_stall(stall_id)
|
stall = await get_shop_stall(stall_id)
|
||||||
if not stall:
|
if not stall:
|
||||||
return {"message": "Withdraw stall does not exist."}
|
return {"message": "Withdraw stall does not exist."}
|
||||||
|
|
||||||
if stall.wallet != wallet.wallet.id:
|
if stall.wallet != wallet.wallet.id:
|
||||||
return {"message": "Not your withdraw stall."}
|
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:
|
else:
|
||||||
stall = await create_diagonalley_stall(data=data)
|
stall = await create_shop_stall(data=data)
|
||||||
|
|
||||||
return stall.dict()
|
return stall.dict()
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.delete("/api/v1/stalls/{stall_id}")
|
@shop_ext.delete("/api/v1/stalls/{stall_id}")
|
||||||
async def api_diagonalley_stall_delete(
|
async def api_shop_stall_delete(
|
||||||
stall_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
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:
|
if not stall:
|
||||||
return {"message": "Stall does not exist."}
|
return {"message": "Stall does not exist."}
|
||||||
|
|
@ -228,44 +228,44 @@ async def api_diagonalley_stall_delete(
|
||||||
if stall.wallet != wallet.wallet.id:
|
if stall.wallet != wallet.wallet.id:
|
||||||
return {"message": "Not your Stall."}
|
return {"message": "Not your Stall."}
|
||||||
|
|
||||||
await delete_diagonalley_stall(stall_id)
|
await delete_shop_stall(stall_id)
|
||||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
###Orders
|
###Orders
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/orders")
|
@shop_ext.get("/api/v1/orders")
|
||||||
async def api_diagonalley_orders(
|
async def api_shop_orders(
|
||||||
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
||||||
):
|
):
|
||||||
wallet_ids = [wallet.wallet.id]
|
wallet_ids = [wallet.wallet.id]
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
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 = []
|
orders_with_details = []
|
||||||
for order in orders:
|
for order in orders:
|
||||||
order = order.dict()
|
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)
|
orders_with_details.append(order)
|
||||||
try:
|
try:
|
||||||
return orders_with_details # [order for order in orders]
|
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:
|
except:
|
||||||
return {"message": "We could not retrieve the orders."}
|
return {"message": "We could not retrieve the orders."}
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/orders/{order_id}")
|
@shop_ext.get("/api/v1/orders/{order_id}")
|
||||||
async def api_diagonalley_order_by_id(order_id: str):
|
async def api_shop_order_by_id(order_id: str):
|
||||||
order = (await get_diagonalley_order(order_id)).dict()
|
order = (await get_shop_order(order_id)).dict()
|
||||||
order["details"] = await get_diagonalley_order_details(order_id)
|
order["details"] = await get_shop_order_details(order_id)
|
||||||
|
|
||||||
return order
|
return order
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.post("/api/v1/orders")
|
@shop_ext.post("/api/v1/orders")
|
||||||
async def api_diagonalley_order_create(data: createOrder):
|
async def api_shop_order_create(data: createOrder):
|
||||||
ref = urlsafe_short_hash()
|
ref = urlsafe_short_hash()
|
||||||
|
|
||||||
payment_hash, payment_request = await create_invoice(
|
payment_hash, payment_request = await create_invoice(
|
||||||
|
|
@ -273,14 +273,14 @@ async def api_diagonalley_order_create(data: createOrder):
|
||||||
amount=data.total,
|
amount=data.total,
|
||||||
memo=f"New order on Diagon alley",
|
memo=f"New order on Diagon alley",
|
||||||
extra={
|
extra={
|
||||||
"tag": "diagonalley",
|
"tag": "shop",
|
||||||
"reference": ref,
|
"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"ORDER ID {order_id}")
|
||||||
logger.debug(f"PRODUCTS {data.products}")
|
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 {
|
return {
|
||||||
"payment_hash": payment_hash,
|
"payment_hash": payment_hash,
|
||||||
"payment_request": payment_request,
|
"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}")
|
@shop_ext.get("/api/v1/orders/payments/{payment_hash}")
|
||||||
async def api_diagonalley_check_payment(payment_hash: str):
|
async def api_shop_check_payment(payment_hash: str):
|
||||||
order = await get_diagonalley_order_invoiceid(payment_hash)
|
order = await get_shop_order_invoiceid(payment_hash)
|
||||||
if not order:
|
if not order:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="Order does not exist."
|
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
|
return status
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.delete("/api/v1/orders/{order_id}")
|
@shop_ext.delete("/api/v1/orders/{order_id}")
|
||||||
async def api_diagonalley_order_delete(
|
async def api_shop_order_delete(
|
||||||
order_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
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:
|
if not order:
|
||||||
return {"message": "Order does not exist."}
|
return {"message": "Order does not exist."}
|
||||||
|
|
@ -316,17 +316,17 @@ async def api_diagonalley_order_delete(
|
||||||
if order.wallet != wallet.wallet.id:
|
if order.wallet != wallet.wallet.id:
|
||||||
return {"message": "Not your Order."}
|
return {"message": "Not your Order."}
|
||||||
|
|
||||||
await delete_diagonalley_order(order_id)
|
await delete_shop_order(order_id)
|
||||||
|
|
||||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/orders/paid/{order_id}")
|
@shop_ext.get("/api/v1/orders/paid/{order_id}")
|
||||||
async def api_diagonalley_order_paid(
|
async def api_shop_order_paid(
|
||||||
order_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
order_id, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||||
):
|
):
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"UPDATE diagonalley.orders SET paid = ? WHERE id = ?",
|
"UPDATE shop.orders SET paid = ? WHERE id = ?",
|
||||||
(
|
(
|
||||||
True,
|
True,
|
||||||
order_id,
|
order_id,
|
||||||
|
|
@ -335,19 +335,19 @@ async def api_diagonalley_order_paid(
|
||||||
return "", HTTPStatus.OK
|
return "", HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/orders/shipped/{order_id}")
|
@shop_ext.get("/api/v1/orders/shipped/{order_id}")
|
||||||
async def api_diagonalley_order_shipped(
|
async def api_shop_order_shipped(
|
||||||
order_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
order_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"UPDATE diagonalley.orders SET shipped = ? WHERE id = ?",
|
"UPDATE shop.orders SET shipped = ? WHERE id = ?",
|
||||||
(
|
(
|
||||||
True,
|
True,
|
||||||
order_id,
|
order_id,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
order = await db.fetchone(
|
order = await db.fetchone(
|
||||||
"SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,)
|
"SELECT * FROM shop.orders WHERE id = ?", (order_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
return order
|
return order
|
||||||
|
|
@ -356,35 +356,35 @@ async def api_diagonalley_order_shipped(
|
||||||
###List products based on stall id
|
###List products based on stall id
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/stall/products/{stall_id}")
|
@shop_ext.get("/api/v1/stall/products/{stall_id}")
|
||||||
async def api_diagonalley_stall_products(
|
async def api_shop_stall_products(
|
||||||
stall_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
stall_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
|
|
||||||
rows = await db.fetchone(
|
rows = await db.fetchone(
|
||||||
"SELECT * FROM diagonalley.stalls WHERE id = ?", (stall_id,)
|
"SELECT * FROM shop.stalls WHERE id = ?", (stall_id,)
|
||||||
)
|
)
|
||||||
if not rows:
|
if not rows:
|
||||||
return {"message": "Stall does not exist."}
|
return {"message": "Stall does not exist."}
|
||||||
|
|
||||||
products = db.fetchone(
|
products = db.fetchone(
|
||||||
"SELECT * FROM diagonalley.products WHERE wallet = ?", (rows[1],)
|
"SELECT * FROM shop.products WHERE wallet = ?", (rows[1],)
|
||||||
)
|
)
|
||||||
if not products:
|
if not products:
|
||||||
return {"message": "No 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
|
###Check a product has been shipped
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/stall/checkshipped/{checking_id}")
|
@shop_ext.get("/api/v1/stall/checkshipped/{checking_id}")
|
||||||
async def api_diagonalley_stall_checkshipped(
|
async def api_shop_stall_checkshipped(
|
||||||
checking_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
checking_id, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
rows = await db.fetchone(
|
rows = await db.fetchone(
|
||||||
"SELECT * FROM diagonalley.orders WHERE invoiceid = ?", (checking_id,)
|
"SELECT * FROM shop.orders WHERE invoiceid = ?", (checking_id,)
|
||||||
)
|
)
|
||||||
return {"shipped": rows["shipped"]}
|
return {"shipped": rows["shipped"]}
|
||||||
|
|
||||||
|
|
@ -392,12 +392,12 @@ async def api_diagonalley_stall_checkshipped(
|
||||||
###Place order
|
###Place order
|
||||||
|
|
||||||
|
|
||||||
# @diagonalley_ext.post("/api/v1/stall/order/{stall_id}")
|
# @shop_ext.post("/api/v1/stall/order/{stall_id}")
|
||||||
# async def api_diagonalley_stall_order(
|
# async def api_shop_stall_order(
|
||||||
# stall_id, data: createOrder, wallet: WalletTypeInfo = Depends(get_key_type)
|
# stall_id, data: createOrder, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
# ):
|
# ):
|
||||||
# product = await get_diagonalley_product(data.productid)
|
# product = await get_shop_product(data.productid)
|
||||||
# shipping = await get_diagonalley_stall(stall_id)
|
# shipping = await get_shop_stall(stall_id)
|
||||||
|
|
||||||
# if data.shippingzone == 1:
|
# if data.shippingzone == 1:
|
||||||
# shippingcost = shipping.zone1cost # missing in model
|
# 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")
|
# selling_id = urlsafe_b64encode(uuid4().bytes_le).decode("utf-8")
|
||||||
# await db.execute(
|
# 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
# VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
# """,
|
# """,
|
||||||
# (
|
# (
|
||||||
|
|
@ -437,43 +437,43 @@ async def api_diagonalley_stall_checkshipped(
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/markets")
|
@shop_ext.get("/api/v1/markets")
|
||||||
async def api_diagonalley_markets(wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_shop_markets(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
# await get_diagonalley_market_stalls(market_id="FzpWnMyHQMcRppiGVua4eY")
|
# await get_shop_market_stalls(market_id="FzpWnMyHQMcRppiGVua4eY")
|
||||||
try:
|
try:
|
||||||
return [
|
return [
|
||||||
market.dict()
|
market.dict()
|
||||||
for market in await get_diagonalley_markets(wallet.wallet.user)
|
for market in await get_shop_markets(wallet.wallet.user)
|
||||||
]
|
]
|
||||||
except:
|
except:
|
||||||
return {"message": "We could not retrieve the markets."}
|
return {"message": "We could not retrieve the markets."}
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/markets/{market_id}/stalls")
|
@shop_ext.get("/api/v1/markets/{market_id}/stalls")
|
||||||
async def api_diagonalley_market_stalls(market_id: str):
|
async def api_shop_market_stalls(market_id: str):
|
||||||
stall_ids = await get_diagonalley_market_stalls(market_id)
|
stall_ids = await get_shop_market_stalls(market_id)
|
||||||
return stall_ids
|
return stall_ids
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.post("/api/v1/markets")
|
@shop_ext.post("/api/v1/markets")
|
||||||
@diagonalley_ext.put("/api/v1/markets/{market_id}")
|
@shop_ext.put("/api/v1/markets/{market_id}")
|
||||||
async def api_diagonalley_stall_create(
|
async def api_shop_stall_create(
|
||||||
data: CreateMarket,
|
data: CreateMarket,
|
||||||
market_id: str = None,
|
market_id: str = None,
|
||||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||||
):
|
):
|
||||||
if market_id:
|
if market_id:
|
||||||
market = await get_diagonalley_market(market_id)
|
market = await get_shop_market(market_id)
|
||||||
if not market:
|
if not market:
|
||||||
return {"message": "Market does not exist."}
|
return {"message": "Market does not exist."}
|
||||||
|
|
||||||
if market.usr != wallet.wallet.user:
|
if market.usr != wallet.wallet.user:
|
||||||
return {"message": "Not your market."}
|
return {"message": "Not your market."}
|
||||||
|
|
||||||
market = await update_diagonalley_market(market_id, **data.dict())
|
market = await update_shop_market(market_id, **data.dict())
|
||||||
else:
|
else:
|
||||||
market = await create_diagonalley_market(data=data)
|
market = await create_shop_market(data=data)
|
||||||
await create_diagonalley_market_stalls(market_id=market.id, data=data.stalls)
|
await create_shop_market_stalls(market_id=market.id, data=data.stalls)
|
||||||
|
|
||||||
return market.dict()
|
return market.dict()
|
||||||
|
|
||||||
|
|
@ -481,8 +481,8 @@ async def api_diagonalley_stall_create(
|
||||||
## KEYS
|
## KEYS
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/keys")
|
@shop_ext.get("/api/v1/keys")
|
||||||
async def api_diagonalley_generate_keys():
|
async def api_shop_generate_keys():
|
||||||
private_key = PrivateKey()
|
private_key = PrivateKey()
|
||||||
public_key = private_key.pubkey.serialize().hex()
|
public_key = private_key.pubkey.serialize().hex()
|
||||||
while not public_key.startswith("02"):
|
while not public_key.startswith("02"):
|
||||||
|
|
@ -494,21 +494,21 @@ async def api_diagonalley_generate_keys():
|
||||||
## MESSAGES/CHAT
|
## MESSAGES/CHAT
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.get("/api/v1/chat/messages/merchant")
|
@shop_ext.get("/api/v1/chat/messages/merchant")
|
||||||
async def api_get_merchant_messages(
|
async def api_get_merchant_messages(
|
||||||
orders: str = Query(...), wallet: WalletTypeInfo = Depends(require_admin_key)
|
orders: str = Query(...), wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||||
):
|
):
|
||||||
|
|
||||||
return [
|
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)):
|
async def api_get_latest_chat_msg(room_name: str, all_messages: bool = Query(False)):
|
||||||
if all_messages:
|
if all_messages:
|
||||||
messages = await get_diagonalley_chat_messages(room_name)
|
messages = await get_shop_chat_messages(room_name)
|
||||||
else:
|
else:
|
||||||
messages = await get_diagonalley_latest_chat_messages(room_name)
|
messages = await get_shop_latest_chat_messages(room_name)
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
Loading…
Add table
Add a link
Reference in a new issue