diff --git a/lnbits/extensions/diagonalley/README.md b/lnbits/extensions/shop/README.md similarity index 53% rename from lnbits/extensions/diagonalley/README.md rename to lnbits/extensions/shop/README.md index e8035b74..86ac9ed9 100644 --- a/lnbits/extensions/diagonalley/README.md +++ b/lnbits/extensions/shop/README.md @@ -1,7 +1,7 @@ -
Each Stall has its own keys!
GET
- /diagonalley/api/v1/stall/products/<relay_id>
POST
- /diagonalley/api/v1/stall/order/<relay_id>
GET
- /diagonalley/api/v1/stall/checkshipped/<checking_id>
Headers
diff --git a/lnbits/extensions/diagonalley/templates/diagonalley/index.html b/lnbits/extensions/shop/templates/shop/index.html
similarity index 96%
rename from lnbits/extensions/diagonalley/templates/diagonalley/index.html
rename to lnbits/extensions/shop/templates/shop/index.html
index 6d98f297..c7261002 100644
--- a/lnbits/extensions/diagonalley/templates/diagonalley/index.html
+++ b/lnbits/extensions/shop/templates/shop/index.html
@@ -253,6 +253,7 @@
>
-
+
Generate keys
-
-
-
- Nostr support coming soon!
-
+ >
+
Create Stall
@@ -398,10 +398,9 @@
- Diagon Alley
+ Shop
- Step inside the Leaky Cauldron and enter the Diagon Alley. Make this
- market available on Nostr!
+ Make a shop of multiple stalls.
@@ -423,9 +422,9 @@
unelevated
color="primary"
@click="shopDataDownload"
- >Download Data
+ >Export all Data
- Download all data (shops, products, orders, etc...)
@@ -703,7 +702,7 @@
icon="storefront"
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
type="a"
- :href="'/diagonalley/stalls/' + props.row.id"
+ :href="'/shop/stalls/' + props.row.id"
target="_blank"
>
Stall simple UI shopping cart
@@ -777,7 +776,7 @@
icon="storefront"
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
type="a"
- :href="'/diagonalley/market/' + props.row.id"
+ :href="'/shop/market/' + props.row.id"
target="_blank"
>
Link to pass to stall relay
@@ -921,16 +920,16 @@
- LNbits Diagon Alley Extension, powered by Nostr
+ LNbits Shop Extension, powered by Nostr
- {% include "diagonalley/_api_docs.html" %}
+ {% include "shop/_api_docs.html" %}
-
+
Messages
@@ -946,6 +945,7 @@
emit-value
>
+
@@ -960,6 +960,7 @@
/>
+
+
+
{
- this.$q.localStorage.remove('lnbits.diagonalley.data')
+ this.$q.localStorage.remove('lnbits.shop.data')
this.user = null
})
},
@@ -342,7 +344,7 @@
return
return await LNbits.api
- .request('GET', `/diagonalley/api/v1/keys`, null)
+ .request('GET', `/shop/api/v1/keys`, null)
.then(response => {
if (response.data) {
let data = {
@@ -363,7 +365,7 @@
await LNbits.api
.request(
'GET',
- `/diagonalley/api/v1/chat/messages/${room_name}${
+ `/shop/api/v1/chat/messages/${room_name}${
all ? '?all_messages=true' : ''
}`
)
@@ -397,14 +399,14 @@
ws_scheme = 'ws://'
}
ws = new WebSocket(
- ws_scheme + location.host + '/diagonalley/ws/' + room_name
+ ws_scheme + location.host + '/shop/ws/' + room_name
)
function checkWebSocket(event) {
if (ws.readyState === WebSocket.CLOSED) {
console.log('WebSocket CLOSED: Reopening')
ws = new WebSocket(
- ws_scheme + location.host + '/diagonalley/ws/' + room_name
+ ws_scheme + location.host + '/shop/ws/' + room_name
)
}
}
@@ -447,7 +449,7 @@
})
let data =
- this.$q.localStorage.getItem(`lnbits.diagonalley.data`) || false
+ this.$q.localStorage.getItem(`lnbits.shop.data`) || false
if (data) {
this.user = data
@@ -468,7 +470,7 @@
await this.getMessages(order_id)
- this.$q.localStorage.set(`lnbits.diagonalley.data`, this.user)
+ this.$q.localStorage.set(`lnbits.shop.data`, this.user)
this.startChat(order_id)
}
})
diff --git a/lnbits/extensions/diagonalley/templates/diagonalley/product.html b/lnbits/extensions/shop/templates/shop/product.html
similarity index 100%
rename from lnbits/extensions/diagonalley/templates/diagonalley/product.html
rename to lnbits/extensions/shop/templates/shop/product.html
diff --git a/lnbits/extensions/diagonalley/templates/diagonalley/stall.html b/lnbits/extensions/shop/templates/shop/stall.html
similarity index 95%
rename from lnbits/extensions/diagonalley/templates/diagonalley/stall.html
rename to lnbits/extensions/shop/templates/shop/stall.html
index 9827ba9b..282fb293 100644
--- a/lnbits/extensions/diagonalley/templates/diagonalley/stall.html
+++ b/lnbits/extensions/shop/templates/shop/stall.html
@@ -76,7 +76,7 @@
{% raw %}
{
this.checkoutDialog = {show: false, data: {}}
@@ -407,7 +409,7 @@
LNbits.api
.request(
'GET',
- `/diagonalley/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
+ `/shop/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
)
.then(res => {
if (res.data.paid) {
@@ -421,7 +423,7 @@
{
label: 'See Order',
handler: () => {
- window.location.href = `/diagonalley/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
+ window.location.href = `/shop/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
}
}
]
@@ -430,7 +432,7 @@
this.resetCart()
this.closeQrCodeDialog()
setTimeout(() => {
- window.location.href = `/diagonalley/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
+ window.location.href = `/shop/order/?merch=${this.stall.id}&invoice_id=${this.qrCodeDialog.data.payment_hash}`
}, 5000)
}
})
diff --git a/lnbits/extensions/diagonalley/views.py b/lnbits/extensions/shop/views.py
similarity index 70%
rename from lnbits/extensions/diagonalley/views.py
rename to lnbits/extensions/shop/views.py
index b87d1918..bb36d683 100644
--- a/lnbits/extensions/diagonalley/views.py
+++ b/lnbits/extensions/shop/views.py
@@ -11,40 +11,40 @@ from starlette.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists # type: ignore
-from lnbits.extensions.diagonalley import diagonalley_ext, diagonalley_renderer
-from lnbits.extensions.diagonalley.models import CreateChatMessage
-from lnbits.extensions.diagonalley.notifier import Notifier
+from lnbits.extensions.shop import shop_ext, shop_renderer
+from lnbits.extensions.shop.models import CreateChatMessage
+from lnbits.extensions.shop.notifier import Notifier
from .crud import (
create_chat_message,
- get_diagonalley_market,
- get_diagonalley_market_stalls,
- get_diagonalley_order_details,
- get_diagonalley_order_invoiceid,
- get_diagonalley_products,
- get_diagonalley_stall,
- get_diagonalley_zone,
- get_diagonalley_zones,
- update_diagonalley_product_stock,
+ get_shop_market,
+ get_shop_market_stalls,
+ get_shop_order_details,
+ get_shop_order_invoiceid,
+ get_shop_products,
+ get_shop_stall,
+ get_shop_zone,
+ get_shop_zones,
+ update_shop_product_stock,
)
templates = Jinja2Templates(directory="templates")
-@diagonalley_ext.get("/", response_class=HTMLResponse)
+@shop_ext.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
- return diagonalley_renderer().TemplateResponse(
- "diagonalley/index.html", {"request": request, "user": user.dict()}
+ return shop_renderer().TemplateResponse(
+ "shop/index.html", {"request": request, "user": user.dict()}
)
-@diagonalley_ext.get("/stalls/{stall_id}", response_class=HTMLResponse)
+@shop_ext.get("/stalls/{stall_id}", response_class=HTMLResponse)
async def display(request: Request, stall_id):
- stall = await get_diagonalley_stall(stall_id)
- products = await get_diagonalley_products(stall_id)
+ stall = await get_shop_stall(stall_id)
+ products = await get_shop_products(stall_id)
zones = []
for id in stall.shippingzones.split(","):
- z = await get_diagonalley_zone(id)
+ z = await get_shop_zone(id)
z = z.dict()
zones.append({"label": z["countries"], "cost": z["cost"], "value": z["id"]})
@@ -57,8 +57,8 @@ async def display(request: Request, stall_id):
del stall["privatekey"]
stall["zones"] = zones
- return diagonalley_renderer().TemplateResponse(
- "diagonalley/stall.html",
+ return shop_renderer().TemplateResponse(
+ "shop/stall.html",
{
"request": request,
"stall": stall,
@@ -67,23 +67,23 @@ async def display(request: Request, stall_id):
)
-@diagonalley_ext.get("/market/{market_id}", response_class=HTMLResponse)
+@shop_ext.get("/market/{market_id}", response_class=HTMLResponse)
async def display(request: Request, market_id):
- market = await get_diagonalley_market(market_id)
+ market = await get_shop_market(market_id)
if not market:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Marketplace doesn't exist."
)
- stalls = await get_diagonalley_market_stalls(market_id)
+ stalls = await get_shop_market_stalls(market_id)
stalls_ids = [stall.id for stall in stalls]
products = [
- product.dict() for product in await get_diagonalley_products(stalls_ids)
+ product.dict() for product in await get_shop_products(stalls_ids)
]
- return diagonalley_renderer().TemplateResponse(
- "diagonalley/market.html",
+ return shop_renderer().TemplateResponse(
+ "shop/market.html",
{
"request": request,
"market": market,
@@ -93,20 +93,20 @@ async def display(request: Request, market_id):
)
-@diagonalley_ext.get("/order", response_class=HTMLResponse)
+@shop_ext.get("/order", response_class=HTMLResponse)
async def chat_page(
request: Request,
merch: str = Query(...),
invoice_id: str = Query(...),
keys: str = Query(None),
):
- stall = await get_diagonalley_stall(merch)
- order = await get_diagonalley_order_invoiceid(invoice_id)
- _order = await get_diagonalley_order_details(order.id)
- products = await get_diagonalley_products(stall.id)
+ stall = await get_shop_stall(merch)
+ order = await get_shop_order_invoiceid(invoice_id)
+ _order = await get_shop_order_details(order.id)
+ products = await get_shop_products(stall.id)
- return diagonalley_renderer().TemplateResponse(
- "diagonalley/order.html",
+ return shop_renderer().TemplateResponse(
+ "shop/order.html",
{
"request": request,
"stall": {
@@ -155,7 +155,7 @@ notifier = Notifier()
# manager = ConnectionManager()
-# @diagonalley_ext.websocket("/ws/{room_name}")
+# @shop_ext.websocket("/ws/{room_name}")
# async def websocket_endpoint(websocket: WebSocket, room_name: str):
# await manager.connect(websocket, room_name)
# try:
@@ -165,7 +165,7 @@ notifier = Notifier()
# manager.disconnect(websocket)
-@diagonalley_ext.websocket("/ws/{room_name}")
+@shop_ext.websocket("/ws/{room_name}")
async def websocket_endpoint(
websocket: WebSocket, room_name: str, background_tasks: BackgroundTasks
):
diff --git a/lnbits/extensions/diagonalley/views_api.py b/lnbits/extensions/shop/views_api.py
similarity index 52%
rename from lnbits/extensions/diagonalley/views_api.py
rename to lnbits/extensions/shop/views_api.py
index b4208847..2899d2a0 100644
--- a/lnbits/extensions/diagonalley/views_api.py
+++ b/lnbits/extensions/shop/views_api.py
@@ -21,41 +21,41 @@ from lnbits.decorators import (
)
from ...helpers import urlsafe_short_hash
-from . import db, diagonalley_ext
+from . import db, shop_ext
from .crud import (
- create_diagonalley_market,
- create_diagonalley_market_stalls,
- create_diagonalley_order,
- create_diagonalley_order_details,
- create_diagonalley_product,
- create_diagonalley_stall,
- create_diagonalley_zone,
- delete_diagonalley_order,
- delete_diagonalley_product,
- delete_diagonalley_stall,
- delete_diagonalley_zone,
- get_diagonalley_chat_by_merchant,
- get_diagonalley_chat_messages,
- get_diagonalley_latest_chat_messages,
- get_diagonalley_market,
- get_diagonalley_market_stalls,
- get_diagonalley_markets,
- get_diagonalley_order,
- get_diagonalley_order_details,
- get_diagonalley_order_invoiceid,
- get_diagonalley_orders,
- get_diagonalley_product,
- get_diagonalley_products,
- get_diagonalley_stall,
- get_diagonalley_stalls,
- get_diagonalley_stalls_by_ids,
- get_diagonalley_zone,
- get_diagonalley_zones,
- set_diagonalley_order_pubkey,
- update_diagonalley_market,
- update_diagonalley_product,
- update_diagonalley_stall,
- update_diagonalley_zone,
+ create_shop_market,
+ create_shop_market_stalls,
+ create_shop_order,
+ create_shop_order_details,
+ create_shop_product,
+ create_shop_stall,
+ create_shop_zone,
+ delete_shop_order,
+ delete_shop_product,
+ delete_shop_stall,
+ delete_shop_zone,
+ get_shop_chat_by_merchant,
+ get_shop_chat_messages,
+ get_shop_latest_chat_messages,
+ get_shop_market,
+ get_shop_market_stalls,
+ get_shop_markets,
+ get_shop_order,
+ get_shop_order_details,
+ get_shop_order_invoiceid,
+ get_shop_orders,
+ get_shop_product,
+ get_shop_products,
+ get_shop_stall,
+ get_shop_stalls,
+ get_shop_stalls_by_ids,
+ get_shop_zone,
+ get_shop_zones,
+ set_shop_order_pubkey,
+ update_shop_market,
+ update_shop_product,
+ update_shop_stall,
+ update_shop_zone,
)
from .models import (
CreateMarket,
@@ -73,8 +73,8 @@ from .models import (
### Products
-@diagonalley_ext.get("/api/v1/products")
-async def api_diagonalley_products(
+@shop_ext.get("/api/v1/products")
+async def api_shop_products(
wallet: WalletTypeInfo = Depends(get_key_type),
all_stalls: bool = Query(False),
):
@@ -83,90 +83,90 @@ async def api_diagonalley_products(
if all_stalls:
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
- stalls = [stall.id for stall in await get_diagonalley_stalls(wallet_ids)]
+ stalls = [stall.id for stall in await get_shop_stalls(wallet_ids)]
if not stalls:
return
- return [product.dict() for product in await get_diagonalley_products(stalls)]
+ return [product.dict() for product in await get_shop_products(stalls)]
-@diagonalley_ext.post("/api/v1/products")
-@diagonalley_ext.put("/api/v1/products/{product_id}")
-async def api_diagonalley_product_create(
+@shop_ext.post("/api/v1/products")
+@shop_ext.put("/api/v1/products/{product_id}")
+async def api_shop_product_create(
data: createProduct, product_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
):
if product_id:
- product = await get_diagonalley_product(product_id)
+ product = await get_shop_product(product_id)
if not product:
return {"message": "Withdraw product does not exist."}
- stall = await get_diagonalley_stall(stall_id=product.stall)
+ stall = await get_shop_stall(stall_id=product.stall)
if stall.wallet != wallet.wallet.id:
return {"message": "Not your withdraw product."}
- product = await update_diagonalley_product(product_id, **data.dict())
+ product = await update_shop_product(product_id, **data.dict())
else:
- product = await create_diagonalley_product(data=data)
+ product = await create_shop_product(data=data)
return product.dict()
-@diagonalley_ext.delete("/api/v1/products/{product_id}")
-async def api_diagonalley_products_delete(
+@shop_ext.delete("/api/v1/products/{product_id}")
+async def api_shop_products_delete(
product_id, wallet: WalletTypeInfo = Depends(require_admin_key)
):
- product = await get_diagonalley_product(product_id)
+ product = await get_shop_product(product_id)
if not product:
return {"message": "Product does not exist."}
- stall = await get_diagonalley_stall(product.stall)
+ stall = await get_shop_stall(product.stall)
if stall.wallet != wallet.wallet.id:
- return {"message": "Not your Diagon Alley."}
+ return {"message": "Not your Shop."}
- await delete_diagonalley_product(product_id)
+ await delete_shop_product(product_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
# # # Shippingzones
-@diagonalley_ext.get("/api/v1/zones")
-async def api_diagonalley_zones(wallet: WalletTypeInfo = Depends(get_key_type)):
+@shop_ext.get("/api/v1/zones")
+async def api_shop_zones(wallet: WalletTypeInfo = Depends(get_key_type)):
- return await get_diagonalley_zones(wallet.wallet.user)
+ return await get_shop_zones(wallet.wallet.user)
-@diagonalley_ext.post("/api/v1/zones")
-async def api_diagonalley_zone_create(
+@shop_ext.post("/api/v1/zones")
+async def api_shop_zone_create(
data: createZones, wallet: WalletTypeInfo = Depends(get_key_type)
):
- zone = await create_diagonalley_zone(user=wallet.wallet.user, data=data)
+ zone = await create_shop_zone(user=wallet.wallet.user, data=data)
return zone.dict()
-@diagonalley_ext.post("/api/v1/zones/{zone_id}")
-async def api_diagonalley_zone_update(
+@shop_ext.post("/api/v1/zones/{zone_id}")
+async def api_shop_zone_update(
data: createZones,
zone_id: str,
wallet: WalletTypeInfo = Depends(require_admin_key),
):
- zone = await get_diagonalley_zone(zone_id)
+ zone = await get_shop_zone(zone_id)
if not zone:
return {"message": "Zone does not exist."}
if zone.user != wallet.wallet.user:
return {"message": "Not your record."}
- zone = await update_diagonalley_zone(zone_id, **data.dict())
+ zone = await update_shop_zone(zone_id, **data.dict())
return zone
-@diagonalley_ext.delete("/api/v1/zones/{zone_id}")
-async def api_diagonalley_zone_delete(
+@shop_ext.delete("/api/v1/zones/{zone_id}")
+async def api_shop_zone_delete(
zone_id, wallet: WalletTypeInfo = Depends(require_admin_key)
):
- zone = await get_diagonalley_zone(zone_id)
+ zone = await get_shop_zone(zone_id)
if not zone:
return {"message": "zone does not exist."}
@@ -174,15 +174,15 @@ async def api_diagonalley_zone_delete(
if zone.user != wallet.wallet.user:
return {"message": "Not your zone."}
- await delete_diagonalley_zone(zone_id)
+ await delete_shop_zone(zone_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
# # # Stalls
-@diagonalley_ext.get("/api/v1/stalls")
-async def api_diagonalley_stalls(
+@shop_ext.get("/api/v1/stalls")
+async def api_shop_stalls(
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
):
wallet_ids = [wallet.wallet.id]
@@ -190,37 +190,37 @@ async def api_diagonalley_stalls(
if all_wallets:
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
- return [stall.dict() for stall in await get_diagonalley_stalls(wallet_ids)]
+ return [stall.dict() for stall in await get_shop_stalls(wallet_ids)]
-@diagonalley_ext.post("/api/v1/stalls")
-@diagonalley_ext.put("/api/v1/stalls/{stall_id}")
-async def api_diagonalley_stall_create(
+@shop_ext.post("/api/v1/stalls")
+@shop_ext.put("/api/v1/stalls/{stall_id}")
+async def api_shop_stall_create(
data: createStalls,
stall_id: str = None,
wallet: WalletTypeInfo = Depends(require_invoice_key),
):
if stall_id:
- stall = await get_diagonalley_stall(stall_id)
+ stall = await get_shop_stall(stall_id)
if not stall:
return {"message": "Withdraw stall does not exist."}
if stall.wallet != wallet.wallet.id:
return {"message": "Not your withdraw stall."}
- stall = await update_diagonalley_stall(stall_id, **data.dict())
+ stall = await update_shop_stall(stall_id, **data.dict())
else:
- stall = await create_diagonalley_stall(data=data)
+ stall = await create_shop_stall(data=data)
return stall.dict()
-@diagonalley_ext.delete("/api/v1/stalls/{stall_id}")
-async def api_diagonalley_stall_delete(
+@shop_ext.delete("/api/v1/stalls/{stall_id}")
+async def api_shop_stall_delete(
stall_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
):
- stall = await get_diagonalley_stall(stall_id)
+ stall = await get_shop_stall(stall_id)
if not stall:
return {"message": "Stall does not exist."}
@@ -228,44 +228,44 @@ async def api_diagonalley_stall_delete(
if stall.wallet != wallet.wallet.id:
return {"message": "Not your Stall."}
- await delete_diagonalley_stall(stall_id)
+ await delete_shop_stall(stall_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
###Orders
-@diagonalley_ext.get("/api/v1/orders")
-async def api_diagonalley_orders(
+@shop_ext.get("/api/v1/orders")
+async def api_shop_orders(
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
):
wallet_ids = [wallet.wallet.id]
if all_wallets:
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
- orders = await get_diagonalley_orders(wallet_ids)
+ orders = await get_shop_orders(wallet_ids)
orders_with_details = []
for order in orders:
order = order.dict()
- order["details"] = await get_diagonalley_order_details(order["id"])
+ order["details"] = await get_shop_order_details(order["id"])
orders_with_details.append(order)
try:
return orders_with_details # [order for order in orders]
- # return [order.dict() for order in await get_diagonalley_orders(wallet_ids)]
+ # return [order.dict() for order in await get_shop_orders(wallet_ids)]
except:
return {"message": "We could not retrieve the orders."}
-@diagonalley_ext.get("/api/v1/orders/{order_id}")
-async def api_diagonalley_order_by_id(order_id: str):
- order = (await get_diagonalley_order(order_id)).dict()
- order["details"] = await get_diagonalley_order_details(order_id)
+@shop_ext.get("/api/v1/orders/{order_id}")
+async def api_shop_order_by_id(order_id: str):
+ order = (await get_shop_order(order_id)).dict()
+ order["details"] = await get_shop_order_details(order_id)
return order
-@diagonalley_ext.post("/api/v1/orders")
-async def api_diagonalley_order_create(data: createOrder):
+@shop_ext.post("/api/v1/orders")
+async def api_shop_order_create(data: createOrder):
ref = urlsafe_short_hash()
payment_hash, payment_request = await create_invoice(
@@ -273,14 +273,14 @@ async def api_diagonalley_order_create(data: createOrder):
amount=data.total,
memo=f"New order on Diagon alley",
extra={
- "tag": "diagonalley",
+ "tag": "shop",
"reference": ref,
},
)
- order_id = await create_diagonalley_order(invoiceid=payment_hash, data=data)
+ order_id = await create_shop_order(invoiceid=payment_hash, data=data)
logger.debug(f"ORDER ID {order_id}")
logger.debug(f"PRODUCTS {data.products}")
- await create_diagonalley_order_details(order_id=order_id, data=data.products)
+ await create_shop_order_details(order_id=order_id, data=data.products)
return {
"payment_hash": payment_hash,
"payment_request": payment_request,
@@ -288,9 +288,9 @@ async def api_diagonalley_order_create(data: createOrder):
}
-@diagonalley_ext.get("/api/v1/orders/payments/{payment_hash}")
-async def api_diagonalley_check_payment(payment_hash: str):
- order = await get_diagonalley_order_invoiceid(payment_hash)
+@shop_ext.get("/api/v1/orders/payments/{payment_hash}")
+async def api_shop_check_payment(payment_hash: str):
+ order = await get_shop_order_invoiceid(payment_hash)
if not order:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Order does not exist."
@@ -304,11 +304,11 @@ async def api_diagonalley_check_payment(payment_hash: str):
return status
-@diagonalley_ext.delete("/api/v1/orders/{order_id}")
-async def api_diagonalley_order_delete(
+@shop_ext.delete("/api/v1/orders/{order_id}")
+async def api_shop_order_delete(
order_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
):
- order = await get_diagonalley_order(order_id)
+ order = await get_shop_order(order_id)
if not order:
return {"message": "Order does not exist."}
@@ -316,17 +316,17 @@ async def api_diagonalley_order_delete(
if order.wallet != wallet.wallet.id:
return {"message": "Not your Order."}
- await delete_diagonalley_order(order_id)
+ await delete_shop_order(order_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
-@diagonalley_ext.get("/api/v1/orders/paid/{order_id}")
-async def api_diagonalley_order_paid(
+@shop_ext.get("/api/v1/orders/paid/{order_id}")
+async def api_shop_order_paid(
order_id, wallet: WalletTypeInfo = Depends(require_admin_key)
):
await db.execute(
- "UPDATE diagonalley.orders SET paid = ? WHERE id = ?",
+ "UPDATE shop.orders SET paid = ? WHERE id = ?",
(
True,
order_id,
@@ -335,19 +335,19 @@ async def api_diagonalley_order_paid(
return "", HTTPStatus.OK
-@diagonalley_ext.get("/api/v1/orders/shipped/{order_id}")
-async def api_diagonalley_order_shipped(
+@shop_ext.get("/api/v1/orders/shipped/{order_id}")
+async def api_shop_order_shipped(
order_id, wallet: WalletTypeInfo = Depends(get_key_type)
):
await db.execute(
- "UPDATE diagonalley.orders SET shipped = ? WHERE id = ?",
+ "UPDATE shop.orders SET shipped = ? WHERE id = ?",
(
True,
order_id,
),
)
order = await db.fetchone(
- "SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,)
+ "SELECT * FROM shop.orders WHERE id = ?", (order_id,)
)
return order
@@ -356,35 +356,35 @@ async def api_diagonalley_order_shipped(
###List products based on stall id
-@diagonalley_ext.get("/api/v1/stall/products/{stall_id}")
-async def api_diagonalley_stall_products(
+@shop_ext.get("/api/v1/stall/products/{stall_id}")
+async def api_shop_stall_products(
stall_id, wallet: WalletTypeInfo = Depends(get_key_type)
):
rows = await db.fetchone(
- "SELECT * FROM diagonalley.stalls WHERE id = ?", (stall_id,)
+ "SELECT * FROM shop.stalls WHERE id = ?", (stall_id,)
)
if not rows:
return {"message": "Stall does not exist."}
products = db.fetchone(
- "SELECT * FROM diagonalley.products WHERE wallet = ?", (rows[1],)
+ "SELECT * FROM shop.products WHERE wallet = ?", (rows[1],)
)
if not products:
return {"message": "No products"}
- return [products.dict() for products in await get_diagonalley_products(rows[1])]
+ return [products.dict() for products in await get_shop_products(rows[1])]
###Check a product has been shipped
-@diagonalley_ext.get("/api/v1/stall/checkshipped/{checking_id}")
-async def api_diagonalley_stall_checkshipped(
+@shop_ext.get("/api/v1/stall/checkshipped/{checking_id}")
+async def api_shop_stall_checkshipped(
checking_id, wallet: WalletTypeInfo = Depends(get_key_type)
):
rows = await db.fetchone(
- "SELECT * FROM diagonalley.orders WHERE invoiceid = ?", (checking_id,)
+ "SELECT * FROM shop.orders WHERE invoiceid = ?", (checking_id,)
)
return {"shipped": rows["shipped"]}
@@ -392,12 +392,12 @@ async def api_diagonalley_stall_checkshipped(
###Place order
-# @diagonalley_ext.post("/api/v1/stall/order/{stall_id}")
-# async def api_diagonalley_stall_order(
+# @shop_ext.post("/api/v1/stall/order/{stall_id}")
+# async def api_shop_stall_order(
# stall_id, data: createOrder, wallet: WalletTypeInfo = Depends(get_key_type)
# ):
-# product = await get_diagonalley_product(data.productid)
-# shipping = await get_diagonalley_stall(stall_id)
+# product = await get_shop_product(data.productid)
+# shipping = await get_shop_stall(stall_id)
# if data.shippingzone == 1:
# shippingcost = shipping.zone1cost # missing in model
@@ -412,7 +412,7 @@ async def api_diagonalley_stall_checkshipped(
# selling_id = urlsafe_b64encode(uuid4().bytes_le).decode("utf-8")
# await db.execute(
# """
-# INSERT INTO diagonalley.orders (id, productid, wallet, product, quantity, shippingzone, address, email, invoiceid, paid, shipped)
+# INSERT INTO shop.orders (id, productid, wallet, product, quantity, shippingzone, address, email, invoiceid, paid, shipped)
# VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
# """,
# (
@@ -437,43 +437,43 @@ async def api_diagonalley_stall_checkshipped(
##
-@diagonalley_ext.get("/api/v1/markets")
-async def api_diagonalley_markets(wallet: WalletTypeInfo = Depends(get_key_type)):
- # await get_diagonalley_market_stalls(market_id="FzpWnMyHQMcRppiGVua4eY")
+@shop_ext.get("/api/v1/markets")
+async def api_shop_markets(wallet: WalletTypeInfo = Depends(get_key_type)):
+ # await get_shop_market_stalls(market_id="FzpWnMyHQMcRppiGVua4eY")
try:
return [
market.dict()
- for market in await get_diagonalley_markets(wallet.wallet.user)
+ for market in await get_shop_markets(wallet.wallet.user)
]
except:
return {"message": "We could not retrieve the markets."}
-@diagonalley_ext.get("/api/v1/markets/{market_id}/stalls")
-async def api_diagonalley_market_stalls(market_id: str):
- stall_ids = await get_diagonalley_market_stalls(market_id)
+@shop_ext.get("/api/v1/markets/{market_id}/stalls")
+async def api_shop_market_stalls(market_id: str):
+ stall_ids = await get_shop_market_stalls(market_id)
return stall_ids
-@diagonalley_ext.post("/api/v1/markets")
-@diagonalley_ext.put("/api/v1/markets/{market_id}")
-async def api_diagonalley_stall_create(
+@shop_ext.post("/api/v1/markets")
+@shop_ext.put("/api/v1/markets/{market_id}")
+async def api_shop_stall_create(
data: CreateMarket,
market_id: str = None,
wallet: WalletTypeInfo = Depends(require_invoice_key),
):
if market_id:
- market = await get_diagonalley_market(market_id)
+ market = await get_shop_market(market_id)
if not market:
return {"message": "Market does not exist."}
if market.usr != wallet.wallet.user:
return {"message": "Not your market."}
- market = await update_diagonalley_market(market_id, **data.dict())
+ market = await update_shop_market(market_id, **data.dict())
else:
- market = await create_diagonalley_market(data=data)
- await create_diagonalley_market_stalls(market_id=market.id, data=data.stalls)
+ market = await create_shop_market(data=data)
+ await create_shop_market_stalls(market_id=market.id, data=data.stalls)
return market.dict()
@@ -481,8 +481,8 @@ async def api_diagonalley_stall_create(
## KEYS
-@diagonalley_ext.get("/api/v1/keys")
-async def api_diagonalley_generate_keys():
+@shop_ext.get("/api/v1/keys")
+async def api_shop_generate_keys():
private_key = PrivateKey()
public_key = private_key.pubkey.serialize().hex()
while not public_key.startswith("02"):
@@ -494,21 +494,21 @@ async def api_diagonalley_generate_keys():
## MESSAGES/CHAT
-@diagonalley_ext.get("/api/v1/chat/messages/merchant")
+@shop_ext.get("/api/v1/chat/messages/merchant")
async def api_get_merchant_messages(
orders: str = Query(...), wallet: WalletTypeInfo = Depends(require_admin_key)
):
return [
- msg.dict() for msg in await get_diagonalley_chat_by_merchant(orders.split(","))
+ msg.dict() for msg in await get_shop_chat_by_merchant(orders.split(","))
]
-@diagonalley_ext.get("/api/v1/chat/messages/{room_name}")
+@shop_ext.get("/api/v1/chat/messages/{room_name}")
async def api_get_latest_chat_msg(room_name: str, all_messages: bool = Query(False)):
if all_messages:
- messages = await get_diagonalley_chat_messages(room_name)
+ messages = await get_shop_chat_messages(room_name)
else:
- messages = await get_diagonalley_latest_chat_messages(room_name)
+ messages = await get_shop_latest_chat_messages(room_name)
return messages