Boltcard view page (#12)
This commit is contained in:
parent
f153c26517
commit
a823cf3e5d
4 changed files with 186 additions and 1 deletions
25
views.py
25
views.py
|
|
@ -1,11 +1,15 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
from fastapi import Depends, Request
|
||||
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
|
||||
|
||||
from . import boltcards_ext, boltcards_renderer
|
||||
from .crud import get_card_by_external_id, get_hits, get_refunds
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
|
@ -15,3 +19,24 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
|
|||
return boltcards_renderer().TemplateResponse(
|
||||
"boltcards/index.html", {"request": request, "user": user.dict()}
|
||||
)
|
||||
|
||||
|
||||
@boltcards_ext.get("/{card_id}", response_class=HTMLResponse)
|
||||
async def display(request: Request, card_id: str):
|
||||
card = await get_card_by_external_id(card_id)
|
||||
if not card:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Card does not exist."
|
||||
)
|
||||
hits = [hit.dict() for hit in await get_hits([card.id])]
|
||||
refunds = [
|
||||
refund.hit_id for refund in await get_refunds([hit["id"] for hit in hits])
|
||||
]
|
||||
card = card.dict()
|
||||
# Remove wallet id from card dict
|
||||
del card["wallet"]
|
||||
|
||||
return boltcards_renderer().TemplateResponse(
|
||||
"boltcards/display.html",
|
||||
{"request": request, "card": card, "hits": hits, "refunds": refunds},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue