feat: update to lnbits 1.0.0 (#41)
--------- Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
parent
239bfb65ab
commit
7f8b269ecd
12 changed files with 1513 additions and 1457 deletions
36
views_api.py
36
views_api.py
|
|
@ -3,7 +3,7 @@ from http import HTTPStatus
|
|||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from lnbits.core.crud import get_user
|
||||
from lnbits.core.models import WalletTypeInfo
|
||||
from lnbits.decorators import get_key_type, require_admin_key
|
||||
from lnbits.decorators import require_admin_key, require_invoice_key
|
||||
|
||||
from .crud import (
|
||||
create_card,
|
||||
|
|
@ -16,22 +16,22 @@ from .crud import (
|
|||
get_refunds,
|
||||
update_card,
|
||||
)
|
||||
from .models import Card, CreateCardData
|
||||
from .models import Card, CreateCardData, Hit, Refund
|
||||
|
||||
boltcards_api_router = APIRouter()
|
||||
|
||||
|
||||
@boltcards_api_router.get("/api/v1/cards")
|
||||
async def api_cards(
|
||||
g: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = False
|
||||
):
|
||||
wallet_ids = [g.wallet.id]
|
||||
key_info: WalletTypeInfo = Depends(require_invoice_key), all_wallets: bool = False
|
||||
) -> list[Card]:
|
||||
wallet_ids = [key_info.wallet.id]
|
||||
|
||||
if all_wallets:
|
||||
user = await get_user(g.wallet.user)
|
||||
user = await get_user(key_info.wallet.user)
|
||||
wallet_ids = user.wallet_ids if user else []
|
||||
|
||||
return [card.dict() for card in await get_cards(wallet_ids)]
|
||||
return await get_cards(wallet_ids)
|
||||
|
||||
|
||||
def validate_card(data: CreateCardData):
|
||||
|
|
@ -146,12 +146,13 @@ async def api_card_delete(card_id, wallet: WalletTypeInfo = Depends(require_admi
|
|||
|
||||
@boltcards_api_router.get("/api/v1/hits")
|
||||
async def api_hits(
|
||||
g: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
||||
):
|
||||
wallet_ids = [g.wallet.id]
|
||||
key_info: WalletTypeInfo = Depends(require_invoice_key),
|
||||
all_wallets: bool = Query(False),
|
||||
) -> list[Hit]:
|
||||
wallet_ids = [key_info.wallet.id]
|
||||
|
||||
if all_wallets:
|
||||
user = await get_user(g.wallet.user)
|
||||
user = await get_user(key_info.wallet.user)
|
||||
wallet_ids = user.wallet_ids if user else []
|
||||
|
||||
cards = await get_cards(wallet_ids)
|
||||
|
|
@ -159,17 +160,18 @@ async def api_hits(
|
|||
for card in cards:
|
||||
cards_ids.append(card.id)
|
||||
|
||||
return [hit.dict() for hit in await get_hits(cards_ids)]
|
||||
return await get_hits(cards_ids)
|
||||
|
||||
|
||||
@boltcards_api_router.get("/api/v1/refunds")
|
||||
async def api_refunds(
|
||||
g: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
||||
):
|
||||
wallet_ids = [g.wallet.id]
|
||||
key_info: WalletTypeInfo = Depends(require_invoice_key),
|
||||
all_wallets: bool = Query(False),
|
||||
) -> list[Refund]:
|
||||
wallet_ids = [key_info.wallet.id]
|
||||
|
||||
if all_wallets:
|
||||
user = await get_user(g.wallet.user)
|
||||
user = await get_user(key_info.wallet.user)
|
||||
wallet_ids = user.wallet_ids if user else []
|
||||
|
||||
cards = await get_cards(wallet_ids)
|
||||
|
|
@ -181,4 +183,4 @@ async def api_refunds(
|
|||
for hit in hits:
|
||||
hits_ids.append(hit.id)
|
||||
|
||||
return [refund.dict() for refund in await get_refunds(hits_ids)]
|
||||
return await get_refunds(hits_ids)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue