mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-10 09:19:42 +01:00
Merge pull request #1269 from lnbits/fix/mypy/events
fix mypy issues for events
This commit is contained in:
commit
fb215ed2e3
4 changed files with 41 additions and 41 deletions
|
@ -1,15 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
|
||||||
from http import HTTPStatus
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
import httpx
|
|
||||||
from fastapi import HTTPException
|
|
||||||
from loguru import logger
|
|
||||||
|
|
||||||
from lnbits import bolt11
|
|
||||||
from lnbits.core.models import Payment
|
from lnbits.core.models import Payment
|
||||||
from lnbits.core.services import pay_invoice
|
|
||||||
from lnbits.extensions.events.models import CreateTicket
|
from lnbits.extensions.events.models import CreateTicket
|
||||||
from lnbits.helpers import get_current_extension_name
|
from lnbits.helpers import get_current_extension_name
|
||||||
from lnbits.tasks import register_invoice_listener
|
from lnbits.tasks import register_invoice_listener
|
||||||
|
@ -29,11 +20,17 @@ async def wait_for_paid_invoices():
|
||||||
async def on_invoice_paid(payment: Payment) -> None:
|
async def on_invoice_paid(payment: Payment) -> None:
|
||||||
# (avoid loops)
|
# (avoid loops)
|
||||||
if (
|
if (
|
||||||
"events" == payment.extra.get("tag")
|
payment.extra
|
||||||
|
and "events" == payment.extra.get("tag")
|
||||||
and payment.extra.get("name")
|
and payment.extra.get("name")
|
||||||
and payment.extra.get("email")
|
and payment.extra.get("email")
|
||||||
):
|
):
|
||||||
CreateTicket.name = str(payment.extra.get("name"))
|
await api_ticket_send_ticket(
|
||||||
CreateTicket.email = str(payment.extra.get("email"))
|
payment.memo,
|
||||||
await api_ticket_send_ticket(payment.memo, payment.payment_hash, CreateTicket)
|
payment.payment_hash,
|
||||||
|
CreateTicket(
|
||||||
|
name=str(payment.extra.get("name")),
|
||||||
|
email=str(payment.extra.get("email")),
|
||||||
|
),
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Depends, Request
|
||||||
from fastapi.params import Depends
|
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.responses import HTMLResponse
|
from starlette.responses import HTMLResponse
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from fastapi.param_functions import Query
|
from fastapi import Depends, Query
|
||||||
from fastapi.params import Depends
|
|
||||||
from loguru import logger
|
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.requests import Request
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -38,7 +35,8 @@ async def api_events(
|
||||||
wallet_ids = [wallet.wallet.id]
|
wallet_ids = [wallet.wallet.id]
|
||||||
|
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
user = await get_user(wallet.wallet.user)
|
||||||
|
wallet_ids = user.wallet_ids if user else []
|
||||||
|
|
||||||
return [event.dict() for event in await get_events(wallet_ids)]
|
return [event.dict() for event in await get_events(wallet_ids)]
|
||||||
|
|
||||||
|
@ -92,7 +90,8 @@ async def api_tickets(
|
||||||
wallet_ids = [wallet.wallet.id]
|
wallet_ids = [wallet.wallet.id]
|
||||||
|
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
user = await get_user(wallet.wallet.user)
|
||||||
|
wallet_ids = user.wallet_ids if user else []
|
||||||
|
|
||||||
return [ticket.dict() for ticket in await get_tickets(wallet_ids)]
|
return [ticket.dict() for ticket in await get_tickets(wallet_ids)]
|
||||||
|
|
||||||
|
@ -119,26 +118,32 @@ async def api_ticket_make_ticket(event_id, name, email):
|
||||||
@events_ext.post("/api/v1/tickets/{event_id}/{payment_hash}")
|
@events_ext.post("/api/v1/tickets/{event_id}/{payment_hash}")
|
||||||
async def api_ticket_send_ticket(event_id, payment_hash, data: CreateTicket):
|
async def api_ticket_send_ticket(event_id, payment_hash, data: CreateTicket):
|
||||||
event = await get_event(event_id)
|
event = await get_event(event_id)
|
||||||
try:
|
if not event:
|
||||||
status = await api_payment(payment_hash)
|
raise HTTPException(
|
||||||
if status["paid"]:
|
status_code=HTTPStatus.NOT_FOUND,
|
||||||
ticket = await create_ticket(
|
detail=f"Event could not be fetched.",
|
||||||
payment_hash=payment_hash,
|
)
|
||||||
wallet=event.wallet,
|
|
||||||
event=event_id,
|
status = await api_payment(payment_hash)
|
||||||
name=data.name,
|
if status["paid"]:
|
||||||
email=data.email,
|
|
||||||
|
exists = await get_ticket(payment_hash)
|
||||||
|
if exists:
|
||||||
|
return {"paid": True, "ticket_id": exists.id}
|
||||||
|
|
||||||
|
ticket = await create_ticket(
|
||||||
|
payment_hash=payment_hash,
|
||||||
|
wallet=event.wallet,
|
||||||
|
event=event_id,
|
||||||
|
name=data.name,
|
||||||
|
email=data.email,
|
||||||
|
)
|
||||||
|
if not ticket:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.NOT_FOUND,
|
||||||
|
detail=f"Event could not be fetched.",
|
||||||
)
|
)
|
||||||
|
return {"paid": True, "ticket_id": ticket.id}
|
||||||
if not ticket:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=HTTPStatus.NOT_FOUND,
|
|
||||||
detail=f"Event could not be fetched.",
|
|
||||||
)
|
|
||||||
|
|
||||||
return {"paid": True, "ticket_id": ticket.id}
|
|
||||||
except Exception:
|
|
||||||
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Not paid")
|
|
||||||
return {"paid": False}
|
return {"paid": False}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,6 @@ exclude = """(?x)(
|
||||||
^lnbits/extensions/bleskomat.
|
^lnbits/extensions/bleskomat.
|
||||||
| ^lnbits/extensions/boltz.
|
| ^lnbits/extensions/boltz.
|
||||||
| ^lnbits/extensions/boltcards.
|
| ^lnbits/extensions/boltcards.
|
||||||
| ^lnbits/extensions/events.
|
|
||||||
| ^lnbits/extensions/gerty.
|
| ^lnbits/extensions/gerty.
|
||||||
| ^lnbits/extensions/invoices.
|
| ^lnbits/extensions/invoices.
|
||||||
| ^lnbits/extensions/livestream.
|
| ^lnbits/extensions/livestream.
|
||||||
|
|
Loading…
Add table
Reference in a new issue