diff --git a/lnbits/extensions/diagonalley/__init__.py b/lnbits/extensions/diagonalley/__init__.py
index 23c02a5f..ec193e3a 100644
--- a/lnbits/extensions/diagonalley/__init__.py
+++ b/lnbits/extensions/diagonalley/__init__.py
@@ -1,10 +1,11 @@
import asyncio
from fastapi import APIRouter
+from starlette.staticfiles import StaticFiles
+
from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
-from starlette.staticfiles import StaticFiles
db = Database("ext_diagonalley")
@@ -26,6 +27,7 @@ diagonalley_static_files = [
# )
# else:
+
def diagonalley_renderer():
return template_renderer(["lnbits/extensions/diagonalley/templates"])
# return template_renderer(["lnbits/extensions/diagonalley/templates"])
diff --git a/lnbits/extensions/diagonalley/crud.py b/lnbits/extensions/diagonalley/crud.py
index b915c81d..8016fd07 100644
--- a/lnbits/extensions/diagonalley/crud.py
+++ b/lnbits/extensions/diagonalley/crud.py
@@ -230,12 +230,15 @@ async def create_diagonalley_order(wallet_id: str, data: createOrder) -> Orders:
False,
),
)
-
+
link = await get_diagonalley_order(order_id)
assert link, "Newly created link couldn't be retrieved"
return link
-async def create_diagonalley_order_details(order_id: str, data: List[createOrderDetails]):
+
+async def create_diagonalley_order_details(
+ order_id: str, data: List[createOrderDetails]
+):
for item in data:
item_id = urlsafe_short_hash()
await db.execute(
@@ -253,6 +256,7 @@ async def create_diagonalley_order_details(order_id: str, data: List[createOrder
order_details = await get_diagonalley_order_details(order_id)
return order_details
+
async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]:
rows = await db.fetchall(
f"SELECT * FROM diagonalley.order_details WHERE order_id = ?", (order_id,)
@@ -260,6 +264,7 @@ async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]:
return [OrderDetail(**row) for row in rows]
+
async def get_diagonalley_order(order_id: str) -> Optional[Orders]:
row = await db.fetchone(
"SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,)
@@ -282,18 +287,18 @@ async def get_diagonalley_orders(wallet_ids: Union[str, List[str]]) -> List[Orde
async def delete_diagonalley_order(order_id: str) -> None:
await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,))
+
### Market/Marketplace
+
async def get_diagonalley_markets(user: str) -> List[Market]:
- rows = await db.fetchall(
- 'SELECT * FROM diagonalley.markets WHERE usr = ?', (user,)
- )
+ rows = await db.fetchall("SELECT * FROM diagonalley.markets WHERE usr = ?", (user,))
return [Market(**row) for row in rows]
async def get_diagonalley_market(market_id: str) -> Optional[Market]:
row = await db.fetchone(
- 'SELECT * FROM diagonalley.markets WHERE id = ?', (market_id,)
+ "SELECT * FROM diagonalley.markets WHERE id = ?", (market_id,)
)
Market(**row) if row else None
@@ -303,5 +308,3 @@ async def get_diagonalley_market_stalls(market_id: str):
"SELECT * FROM diagonalley.market_stalls WHERE marketid = ?", (market_id,)
)
return [Stalls(**row) for row in rows]
-
-
diff --git a/lnbits/extensions/diagonalley/migrations.py b/lnbits/extensions/diagonalley/migrations.py
index 8a65df8a..a7380b65 100644
--- a/lnbits/extensions/diagonalley/migrations.py
+++ b/lnbits/extensions/diagonalley/migrations.py
@@ -111,4 +111,3 @@ async def m001_initial(db):
);
"""
)
-
diff --git a/lnbits/extensions/diagonalley/models.py b/lnbits/extensions/diagonalley/models.py
index 737f2b4b..f07e9c80 100644
--- a/lnbits/extensions/diagonalley/models.py
+++ b/lnbits/extensions/diagonalley/models.py
@@ -55,12 +55,14 @@ class Zones(BaseModel):
cost: int
countries: str
+
class OrderDetail(BaseModel):
id: str
order_id: str
product_id: str
quantity: int
+
class createOrderDetails(BaseModel):
product_id: str = Query(...)
quantity: int = Query(..., ge=1)
@@ -95,11 +97,13 @@ class Orders(BaseModel):
shipped: bool
time: int
+
class CreateMarket(BaseModel):
usr: str = Query(...)
name: str = Query(None)
stalls: List[str] = Query(...)
+
class Market(BaseModel):
id: str
usr: str
diff --git a/lnbits/extensions/diagonalley/templates/diagonalley/_api_docs.html b/lnbits/extensions/diagonalley/templates/diagonalley/_api_docs.html
index 530c89e8..5418deba 100644
--- a/lnbits/extensions/diagonalley/templates/diagonalley/_api_docs.html
+++ b/lnbits/extensions/diagonalley/templates/diagonalley/_api_docs.html
@@ -9,26 +9,28 @@
Diagon Alley: Decentralised Market-Stalls
-
- Each Stall has its own keys!
-
- - Create Shipping Zones you're willing to ship to
- - Create a Stall to list yiur products on
- - Create products to put on the Stall
- - List stalls on a simple frontend shop page, or point at Nostr shop client key
-
- Make a list of products to sell, point your list of products at a public
- relay. Buyers browse your products on the relay, and pay you directly.
- Ratings are managed by the relay. Your stall can be listed in multiple
- relays, even over TOR, if you wish to be anonymous.
- More information on the
- Diagon Alley Protocol
-
- Created by, Ben Arc
-
+ Each Stall has its own keys!
+
+
+ - Create Shipping Zones you're willing to ship to
+ - Create a Stall to list yiur products on
+ - Create products to put on the Stall
+ -
+ List stalls on a simple frontend shop page, or point at Nostr shop
+ client key
+
+
+ Make a list of products to sell, point your list of products at a public
+ relay. Buyers browse your products on the relay, and pay you directly.
+ Ratings are managed by the relay. Your stall can be listed in multiple
+ relays, even over TOR, if you wish to be anonymous.
+ More information on the
+ Diagon Alley Protocol
+
+ Created by, Ben Arc
+
diff --git a/lnbits/extensions/diagonalley/templates/diagonalley/index.html b/lnbits/extensions/diagonalley/templates/diagonalley/index.html
index 893830a9..5482cd3f 100644
--- a/lnbits/extensions/diagonalley/templates/diagonalley/index.html
+++ b/lnbits/extensions/diagonalley/templates/diagonalley/index.html
@@ -28,7 +28,7 @@
label="Description"
>
-
-
-
-
+
+
+
Create Product
- Cancel
@@ -162,7 +167,12 @@
>Create Shipping Zone
- Cancel
@@ -174,10 +184,10 @@
+ label="Activate shop"
+ color="primary"
+ v-model="marketDialog.data.activate"
+ >
Launch
- Cancel
@@ -284,7 +299,9 @@
v-model.trim="stallDialog.data.nostrShops"
label="Nostr shop public keys (seperate by comma)"
> -->
- Nostr support coming soon!
+
+ Nostr support coming soon!
+
Create Store
- Cancel
@@ -313,33 +335,50 @@
-
- + Product List a product
- + Product List a product
+ Shipping Zone Create a shipping zone
- + Store
Create a stall to list products on
- + Store
Create a store to list products on
Launch frontend shop (not Nostr)
- Makes a simple frontend shop for your stalls
+ Makes a simple frontend shop for your stalls
-
-
-
+
+
+
@@ -403,7 +442,8 @@
-
+
+
@@ -482,8 +522,9 @@
-
-
+
+
+
@@ -555,8 +596,9 @@
-
-
+
+
+
@@ -632,14 +674,18 @@
Messages
-
+
-
+
-
+
@@ -648,14 +694,11 @@
:text="[message[1]]"
sent
>
-
-
+
+
-
+
@@ -665,934 +708,935 @@
-
-
+
{% endblock %} {% block scripts %} {{ window_vars(user) }}
{% endblock %}
-
diff --git a/lnbits/extensions/diagonalley/views.py b/lnbits/extensions/diagonalley/views.py
index 08c30428..30dbebe7 100644
--- a/lnbits/extensions/diagonalley/views.py
+++ b/lnbits/extensions/diagonalley/views.py
@@ -34,16 +34,17 @@ async def display(request: Request, stall_id):
stall = stall.dict()
del stall["privatekey"]
-
+
return diagonalley_renderer().TemplateResponse(
"diagonalley/stall.html",
{
"request": request,
"stall": stall,
- "products": [product.dict() for product in products]
+ "products": [product.dict() for product in products],
},
)
+
# @diagonalley_ext.get("/market/{market_id}", response_class=HTMLResponse)
# async def display(request: Request, stall_id):
# stalls = await get_diagonalley_stall(stall_id)
diff --git a/lnbits/extensions/diagonalley/views_api.py b/lnbits/extensions/diagonalley/views_api.py
index b2fb5a47..cedd1d42 100644
--- a/lnbits/extensions/diagonalley/views_api.py
+++ b/lnbits/extensions/diagonalley/views_api.py
@@ -5,6 +5,8 @@ from uuid import uuid4
from fastapi import Request
from fastapi.param_functions import Query
from fastapi.params import Depends
+from starlette.exceptions import HTTPException
+
from lnbits.core.crud import get_user
from lnbits.core.services import create_invoice
from lnbits.decorators import (
@@ -13,7 +15,6 @@ from lnbits.decorators import (
require_admin_key,
require_invoice_key,
)
-from starlette.exceptions import HTTPException
from . import db, diagonalley_ext
from .crud import (
@@ -94,22 +95,22 @@ async def api_diagonalley_products(
@diagonalley_ext.post("/api/v1/products")
@diagonalley_ext.put("/api/v1/products/{product_id}")
async def api_diagonalley_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:
- product = await get_diagonalley_product(product_id)
+ product = await get_diagonalley_product(product_id)
if not product:
return {"message": "Withdraw product does not exist."}
-
- stall = await get_diagonalley_stall(stall_id = product.stall)
+
+ stall = await get_diagonalley_stall(stall_id=product.stall)
if stall.wallet != wallet.wallet.id:
return {"message": "Not your withdraw product."}
product = await update_diagonalley_product(product_id, **data.dict())
else:
product = await create_diagonalley_product(data=data)
-
+
return product.dict()
@@ -392,15 +393,18 @@ async def api_diagonalley_stall_order(
# MARKETS
##
+
@diagonalley_ext.get("/api/v1/markets")
-async def api_diagonalley_orders(
- wallet: WalletTypeInfo = Depends(get_key_type)
-):
+async def api_diagonalley_orders(wallet: WalletTypeInfo = Depends(get_key_type)):
try:
- return [market.dict() for market in await get_diagonalley_markets(wallet.wallet.user)]
+ return [
+ market.dict()
+ for market in await get_diagonalley_markets(wallet.wallet.user)
+ ]
except:
return {"message": "We could not retrieve the markets."}
+
@diagonalley_ext.post("/api/v1/markets")
@diagonalley_ext.put("/api/v1/markets/{market_id}")
async def api_diagonalley_stall_create(