I want them to turn black
This commit is contained in:
@@ -14,12 +14,9 @@ tpos_ext: APIRouter = APIRouter(
|
||||
# "tpos", __name__, static_folder="static", template_folder="templates"
|
||||
)
|
||||
|
||||
|
||||
def tpos_renderer():
|
||||
return template_renderer(
|
||||
[
|
||||
"lnbits/extensions/tpos/templates",
|
||||
]
|
||||
)
|
||||
return template_renderer(["lnbits/extensions/tpos/templates"])
|
||||
|
||||
|
||||
from .views_api import * # noqa
|
||||
|
||||
@@ -7,6 +7,7 @@ class CreateTposData(BaseModel):
|
||||
name: str
|
||||
currency: str
|
||||
|
||||
|
||||
class TPoS(BaseModel):
|
||||
id: str
|
||||
wallet: str
|
||||
|
||||
@@ -13,11 +13,14 @@ from fastapi.templating import Jinja2Templates
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@tpos_ext.get("/", response_class=HTMLResponse)
|
||||
# @validate_uuids(["usr"], required=True)
|
||||
# @check_user_exists()
|
||||
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||
return tpos_renderer().TemplateResponse("tpos/index.html", {"request": request,"user": user.dict()})
|
||||
return tpos_renderer().TemplateResponse(
|
||||
"tpos/index.html", {"request": request, "user": user.dict()}
|
||||
)
|
||||
|
||||
|
||||
@tpos_ext.get("/{tpos_id}")
|
||||
@@ -25,9 +28,10 @@ async def tpos(request: Request, tpos_id):
|
||||
tpos = await get_tpos(tpos_id)
|
||||
if not tpos:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="TPoS does not exist."
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
||||
)
|
||||
# abort(HTTPStatus.NOT_FOUND, "TPoS does not exist.")
|
||||
|
||||
return tpos_renderer().TemplateResponse("tpos/tpos.html", {"request": request, "tpos": tpos})
|
||||
return tpos_renderer().TemplateResponse(
|
||||
"tpos/tpos.html", {"request": request, "tpos": tpos}
|
||||
)
|
||||
|
||||
@@ -19,18 +19,19 @@ from .models import TPoS, CreateTposData
|
||||
|
||||
@tpos_ext.get("/api/v1/tposs", status_code=HTTPStatus.OK)
|
||||
async def api_tposs(
|
||||
all_wallets: bool = Query(None),
|
||||
wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
all_wallets: bool = Query(None), wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
wallet_ids = [wallet.wallet.id]
|
||||
if all_wallets:
|
||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||
|
||||
return [tpos.dict() for tpos in await get_tposs(wallet_ids)]
|
||||
|
||||
|
||||
@tpos_ext.post("/api/v1/tposs", status_code=HTTPStatus.CREATED)
|
||||
async def api_tpos_create(data: CreateTposData, wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
async def api_tpos_create(
|
||||
data: CreateTposData, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
tpos = await create_tpos(wallet_id=wallet.wallet.id, data=data)
|
||||
return tpos.dict()
|
||||
|
||||
@@ -41,30 +42,26 @@ async def api_tpos_delete(tpos_id: str, wallet: WalletTypeInfo = Depends(get_key
|
||||
|
||||
if not tpos:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="TPoS does not exist."
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
||||
)
|
||||
# return {"message": "TPoS does not exist."}, HTTPStatus.NOT_FOUND
|
||||
|
||||
if tpos.wallet != wallet.wallet.id:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.FORBIDDEN,
|
||||
detail="Not your TPoS."
|
||||
)
|
||||
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your TPoS.")
|
||||
# return {"message": "Not your TPoS."}, HTTPStatus.FORBIDDEN
|
||||
|
||||
await delete_tpos(tpos_id)
|
||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||
# return "", HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
@tpos_ext.post("/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED)
|
||||
async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str = None):
|
||||
tpos = await get_tpos(tpos_id)
|
||||
|
||||
if not tpos:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="TPoS does not exist."
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
||||
)
|
||||
# return {"message": "TPoS does not exist."}, HTTPStatus.NOT_FOUND
|
||||
|
||||
@@ -76,22 +73,20 @@ async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str =
|
||||
extra={"tag": "tpos"},
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail=str(e)
|
||||
)
|
||||
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
|
||||
# return {"message": str(e)}, HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
return {"payment_hash": payment_hash, "payment_request": payment_request}
|
||||
|
||||
|
||||
@tpos_ext.get("/api/v1/tposs/{tpos_id}/invoices/{payment_hash}", status_code=HTTPStatus.OK)
|
||||
@tpos_ext.get(
|
||||
"/api/v1/tposs/{tpos_id}/invoices/{payment_hash}", status_code=HTTPStatus.OK
|
||||
)
|
||||
async def api_tpos_check_invoice(tpos_id: str, payment_hash: str):
|
||||
tpos = await get_tpos(tpos_id)
|
||||
if not tpos:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="TPoS does not exist."
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
||||
)
|
||||
# return {"message": "TPoS does not exist."}, HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
Reference in New Issue
Block a user