make format diagonalley
This commit is contained in:
parent
39bae68b1c
commit
58b046254f
8 changed files with 1037 additions and 978 deletions
|
|
@ -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"])
|
||||
|
|
|
|||
|
|
@ -235,7 +235,10 @@ async def create_diagonalley_order(wallet_id: str, data: createOrder) -> Orders:
|
|||
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]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -111,4 +111,3 @@ async def m001_initial(db):
|
|||
);
|
||||
"""
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -9,26 +9,28 @@
|
|||
<h5 class="text-subtitle1 q-my-none">
|
||||
Diagon Alley: Decentralised Market-Stalls
|
||||
</h5>
|
||||
<p>
|
||||
Each Stall has its own keys!<br />
|
||||
<ol>
|
||||
<li>Create Shipping Zones you're willing to ship to</li>
|
||||
<li>Create a Stall to list yiur products on</li>
|
||||
<li>Create products to put on the Stall</li>
|
||||
<li>List stalls on a simple frontend shop page, or point at Nostr shop client key</li>
|
||||
</ol>
|
||||
Make a list of products to sell, point your list of products at a public
|
||||
relay. Buyers browse your products on the relay, and pay you directly.
|
||||
Ratings are managed by the relay. Your stall can be listed in multiple
|
||||
relays, even over TOR, if you wish to be anonymous.<br />
|
||||
More information on the
|
||||
<a href="https://github.com/lnbits/Diagon-Alley"
|
||||
>Diagon Alley Protocol</a
|
||||
><br />
|
||||
<small>
|
||||
Created by, <a href="https://github.com/benarc">Ben Arc</a></small
|
||||
>
|
||||
</p>
|
||||
<p>Each Stall has its own keys!<br /></p>
|
||||
|
||||
<ol>
|
||||
<li>Create Shipping Zones you're willing to ship to</li>
|
||||
<li>Create a Stall to list yiur products on</li>
|
||||
<li>Create products to put on the Stall</li>
|
||||
<li>
|
||||
List stalls on a simple frontend shop page, or point at Nostr shop
|
||||
client key
|
||||
</li>
|
||||
</ol>
|
||||
Make a list of products to sell, point your list of products at a public
|
||||
relay. Buyers browse your products on the relay, and pay you directly.
|
||||
Ratings are managed by the relay. Your stall can be listed in multiple
|
||||
relays, even over TOR, if you wish to be anonymous.<br />
|
||||
More information on the
|
||||
<a href="https://github.com/lnbits/Diagon-Alley">Diagon Alley Protocol</a
|
||||
><br />
|
||||
<small>
|
||||
Created by, <a href="https://github.com/benarc">Ben Arc</a></small
|
||||
>
|
||||
<!-- </p> -->
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</q-expansion-item>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -40,10 +40,11 @@ async def display(request: Request, stall_id):
|
|||
{
|
||||
"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)
|
||||
|
|
|
|||
|
|
@ -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,7 +95,7 @@ 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:
|
||||
|
|
@ -102,7 +103,7 @@ async def api_diagonalley_product_create(
|
|||
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."}
|
||||
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue