make format diagonalley

This commit is contained in:
Tiago vasconcelos 2022-08-16 12:19:31 +01:00
parent 39bae68b1c
commit 58b046254f
8 changed files with 1037 additions and 978 deletions

View file

@ -1,10 +1,11 @@
import asyncio import asyncio
from fastapi import APIRouter from fastapi import APIRouter
from starlette.staticfiles import StaticFiles
from lnbits.db import Database 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
from starlette.staticfiles import StaticFiles
db = Database("ext_diagonalley") db = Database("ext_diagonalley")
@ -26,6 +27,7 @@ diagonalley_static_files = [
# ) # )
# else: # else:
def diagonalley_renderer(): def diagonalley_renderer():
return template_renderer(["lnbits/extensions/diagonalley/templates"]) return template_renderer(["lnbits/extensions/diagonalley/templates"])
# return template_renderer(["lnbits/extensions/diagonalley/templates"]) # return template_renderer(["lnbits/extensions/diagonalley/templates"])

View file

@ -230,12 +230,15 @@ async def create_diagonalley_order(wallet_id: str, data: createOrder) -> Orders:
False, False,
), ),
) )
link = await get_diagonalley_order(order_id) link = await get_diagonalley_order(order_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(order_id: str, data: List[createOrderDetails]):
async def create_diagonalley_order_details(
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(
@ -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) order_details = await get_diagonalley_order_details(order_id)
return order_details return order_details
async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]: async def get_diagonalley_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 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] return [OrderDetail(**row) for row in rows]
async def get_diagonalley_order(order_id: str) -> Optional[Orders]: async def get_diagonalley_order(order_id: str) -> Optional[Orders]:
row = await db.fetchone( row = await db.fetchone(
"SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,) "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: async def delete_diagonalley_order(order_id: str) -> None:
await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,)) await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,))
### Market/Marketplace ### Market/Marketplace
async def get_diagonalley_markets(user: str) -> List[Market]: async def get_diagonalley_markets(user: str) -> List[Market]:
rows = await db.fetchall( rows = await db.fetchall("SELECT * FROM diagonalley.markets WHERE usr = ?", (user,))
'SELECT * FROM diagonalley.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_diagonalley_market(market_id: str) -> Optional[Market]:
row = await db.fetchone( 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 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,) "SELECT * FROM diagonalley.market_stalls WHERE marketid = ?", (market_id,)
) )
return [Stalls(**row) for row in rows] return [Stalls(**row) for row in rows]

View file

@ -111,4 +111,3 @@ async def m001_initial(db):
); );
""" """
) )

View file

@ -55,12 +55,14 @@ class Zones(BaseModel):
cost: int cost: int
countries: str countries: str
class OrderDetail(BaseModel): class OrderDetail(BaseModel):
id: str id: str
order_id: str order_id: str
product_id: str product_id: str
quantity: int quantity: int
class createOrderDetails(BaseModel): class createOrderDetails(BaseModel):
product_id: str = Query(...) product_id: str = Query(...)
quantity: int = Query(..., ge=1) quantity: int = Query(..., ge=1)
@ -95,11 +97,13 @@ class Orders(BaseModel):
shipped: bool shipped: bool
time: int time: int
class CreateMarket(BaseModel): class CreateMarket(BaseModel):
usr: str = Query(...) usr: str = Query(...)
name: str = Query(None) name: str = Query(None)
stalls: List[str] = Query(...) stalls: List[str] = Query(...)
class Market(BaseModel): class Market(BaseModel):
id: str id: str
usr: str usr: str

View file

@ -9,26 +9,28 @@
<h5 class="text-subtitle1 q-my-none"> <h5 class="text-subtitle1 q-my-none">
Diagon Alley: Decentralised Market-Stalls Diagon Alley: Decentralised Market-Stalls
</h5> </h5>
<p> <p>Each Stall has its own keys!<br /></p>
Each Stall has its own keys!<br />
<ol> <ol>
<li>Create Shipping Zones you're willing to ship to</li> <li>Create Shipping Zones you're willing to ship to</li>
<li>Create a Stall to list yiur products on</li> <li>Create a Stall to list yiur products on</li>
<li>Create products to put on the Stall</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> <li>
</ol> List stalls on a simple frontend shop page, or point at Nostr shop
Make a list of products to sell, point your list of products at a public client key
relay. Buyers browse your products on the relay, and pay you directly. </li>
Ratings are managed by the relay. Your stall can be listed in multiple </ol>
relays, even over TOR, if you wish to be anonymous.<br /> Make a list of products to sell, point your list of products at a public
More information on the relay. Buyers browse your products on the relay, and pay you directly.
<a href="https://github.com/lnbits/Diagon-Alley" Ratings are managed by the relay. Your stall can be listed in multiple
>Diagon Alley Protocol</a relays, even over TOR, if you wish to be anonymous.<br />
><br /> More information on the
<small> <a href="https://github.com/lnbits/Diagon-Alley">Diagon Alley Protocol</a
Created by, <a href="https://github.com/benarc">Ben Arc</a></small ><br />
> <small>
</p> Created by, <a href="https://github.com/benarc">Ben Arc</a></small
>
<!-- </p> -->
</q-card-section> </q-card-section>
</q-card> </q-card>
</q-expansion-item> </q-expansion-item>

File diff suppressed because it is too large Load diff

View file

@ -34,16 +34,17 @@ async def display(request: Request, stall_id):
stall = stall.dict() stall = stall.dict()
del stall["privatekey"] del stall["privatekey"]
return diagonalley_renderer().TemplateResponse( return diagonalley_renderer().TemplateResponse(
"diagonalley/stall.html", "diagonalley/stall.html",
{ {
"request": request, "request": request,
"stall": stall, "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) # @diagonalley_ext.get("/market/{market_id}", response_class=HTMLResponse)
# async def display(request: Request, stall_id): # async def display(request: Request, stall_id):
# stalls = await get_diagonalley_stall(stall_id) # stalls = await get_diagonalley_stall(stall_id)

View file

@ -5,6 +5,8 @@ from uuid import uuid4
from fastapi import Request from fastapi import Request
from fastapi.param_functions import Query from fastapi.param_functions import Query
from fastapi.params import Depends from fastapi.params import Depends
from starlette.exceptions import HTTPException
from lnbits.core.crud import get_user from lnbits.core.crud import get_user
from lnbits.core.services import create_invoice from lnbits.core.services import create_invoice
from lnbits.decorators import ( from lnbits.decorators import (
@ -13,7 +15,6 @@ from lnbits.decorators import (
require_admin_key, require_admin_key,
require_invoice_key, require_invoice_key,
) )
from starlette.exceptions import HTTPException
from . import db, diagonalley_ext from . import db, diagonalley_ext
from .crud import ( from .crud import (
@ -94,22 +95,22 @@ async def api_diagonalley_products(
@diagonalley_ext.post("/api/v1/products") @diagonalley_ext.post("/api/v1/products")
@diagonalley_ext.put("/api/v1/products/{product_id}") @diagonalley_ext.put("/api/v1/products/{product_id}")
async def api_diagonalley_product_create( 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: if product_id:
product = await get_diagonalley_product(product_id) product = await get_diagonalley_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_diagonalley_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_diagonalley_product(product_id, **data.dict())
else: else:
product = await create_diagonalley_product(data=data) product = await create_diagonalley_product(data=data)
return product.dict() return product.dict()
@ -392,15 +393,18 @@ async def api_diagonalley_stall_order(
# MARKETS # MARKETS
## ##
@diagonalley_ext.get("/api/v1/markets") @diagonalley_ext.get("/api/v1/markets")
async def api_diagonalley_orders( async def api_diagonalley_orders(wallet: WalletTypeInfo = Depends(get_key_type)):
wallet: WalletTypeInfo = Depends(get_key_type)
):
try: 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: except:
return {"message": "We could not retrieve the markets."} return {"message": "We could not retrieve the markets."}
@diagonalley_ext.post("/api/v1/markets") @diagonalley_ext.post("/api/v1/markets")
@diagonalley_ext.put("/api/v1/markets/{market_id}") @diagonalley_ext.put("/api/v1/markets/{market_id}")
async def api_diagonalley_stall_create( async def api_diagonalley_stall_create(