UI fires up

This commit is contained in:
Tiago vasconcelos
2022-07-18 09:11:19 +01:00
parent c41f6033be
commit a55dd18528
4 changed files with 55 additions and 49 deletions
+23 -32
View File
@@ -1,44 +1,35 @@
from typing import List
from fastapi import Request, WebSocket, WebSocketDisconnect
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.responses import HTMLResponse # type: ignore
from http import HTTPStatus
import json
from lnbits.decorators import check_user_exists, validate_uuids
from lnbits.extensions.diagonalley import diagonalley_ext
from .crud import (
create_diagonalley_product,
get_diagonalley_product,
get_diagonalley_products,
delete_diagonalley_product,
create_diagonalley_order,
get_diagonalley_order,
get_diagonalley_orders,
update_diagonalley_product,
)
from fastapi import Request
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException
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 .crud import get_diagonalley_products
templates = Jinja2Templates(directory="templates")
@diagonalley_ext.get("/", response_class=HTMLResponse)
@validate_uuids(["usr"], required=True)
@check_user_exists(request: Request)
async def index():
return await render_template("diagonalley/index.html", user=g.user)
async def index(request: Request, user: User = Depends(check_user_exists)):
return diagonalley_renderer().TemplateResponse(
"diagonalley/index.html", {"request": request, "user": user.dict()}
)
@diagonalley_ext.get("/<stall_id>", response_class=HTMLResponse)
@diagonalley_ext.get("/{stall_id}", response_class=HTMLResponse)
async def display(request: Request, stall_id):
product = await get_diagonalley_products(stall_id)
if not product:
abort(HTTPStatus.NOT_FOUND, "Stall does not exist.")
return await render_template(
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Stall does not exist."
)
return diagonalley_renderer().TemplateResponse(
"diagonalley/stall.html",
stall=json.dumps(
[product._asdict() for product in await get_diagonalley_products(stall_id)]
),
{"stall": [product.dict() for product in await get_diagonalley_products(stall_id)]}
)