FEAT: Filters for GET requests, add it to GET /payments (#1557)
* feat filters, add them to GET payments * add limit and offset to filters (#1563) * add limit and offset to filters * move filters example to parse_filters doc string * black * add openapi docs * remove example commentC * improve typing and make nested filter possible in openapi * typo in fn name * readd Type --------- Co-authored-by: jackstar12 <62219658+jackstar12@users.noreply.github.com> Co-authored-by: calle <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
co-authored by
jackstar12
calle
parent
fe9e821af5
commit
8ce84ce592
@@ -34,10 +34,12 @@ from lnbits.core.helpers import (
|
||||
stop_extension_background_work,
|
||||
)
|
||||
from lnbits.core.models import Payment, User, Wallet
|
||||
from lnbits.db import Filters
|
||||
from lnbits.decorators import (
|
||||
WalletTypeInfo,
|
||||
check_admin,
|
||||
get_key_type,
|
||||
parse_filters,
|
||||
require_admin_key,
|
||||
require_invoice_key,
|
||||
)
|
||||
@@ -48,7 +50,7 @@ from lnbits.extension_manager import (
|
||||
InstallableExtension,
|
||||
get_valid_extensions,
|
||||
)
|
||||
from lnbits.helpers import url_for
|
||||
from lnbits.helpers import generate_filter_params_openapi, url_for
|
||||
from lnbits.settings import get_wallet_class, settings
|
||||
from lnbits.utils.exchange_rates import (
|
||||
currencies,
|
||||
@@ -114,18 +116,23 @@ async def api_update_wallet(
|
||||
}
|
||||
|
||||
|
||||
@core_app.get("/api/v1/payments")
|
||||
@core_app.get(
|
||||
"/api/v1/payments",
|
||||
name="Payment List",
|
||||
summary="get list of payments",
|
||||
response_description="list of payments",
|
||||
response_model=List[Payment],
|
||||
openapi_extra=generate_filter_params_openapi(Payment),
|
||||
)
|
||||
async def api_payments(
|
||||
limit: Optional[int] = None,
|
||||
offset: Optional[int] = None,
|
||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||
filters: Filters = Depends(parse_filters(Payment)),
|
||||
):
|
||||
pendingPayments = await get_payments(
|
||||
wallet_id=wallet.wallet.id,
|
||||
pending=True,
|
||||
exclude_uncheckable=True,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
filters=filters,
|
||||
)
|
||||
for payment in pendingPayments:
|
||||
await check_transaction_status(
|
||||
@@ -135,8 +142,7 @@ async def api_payments(
|
||||
wallet_id=wallet.wallet.id,
|
||||
pending=True,
|
||||
complete=True,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
filters=filters,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user