Adds pagination to transaction history

Implements pagination for the transaction history, enabling users
to navigate through their transactions in manageable chunks. This
improves performance and user experience, especially for users
with a large number of transactions. It also introduces total entry counts.
This commit is contained in:
padreug 2025-11-08 23:51:12 +01:00
parent 4b327a0aab
commit 69b8f6e2d3
4 changed files with 120 additions and 12 deletions

View file

@ -265,16 +265,29 @@ async def api_get_journal_entries(limit: int = 100) -> list[JournalEntry]:
@castle_api_router.get("/api/v1/entries/user")
async def api_get_user_entries(
wallet: WalletTypeInfo = Depends(require_invoice_key),
limit: int = 100,
) -> list[JournalEntry]:
limit: int = 20,
offset: int = 0,
) -> dict:
"""Get journal entries that affect the current user's accounts"""
from lnbits.settings import settings as lnbits_settings
from .crud import count_all_journal_entries, count_journal_entries_by_user
# If super user, show all journal entries
if wallet.wallet.user == lnbits_settings.super_user:
return await get_all_journal_entries(limit)
entries = await get_all_journal_entries(limit, offset)
total = await count_all_journal_entries()
else:
entries = await get_journal_entries_by_user(wallet.wallet.user, limit, offset)
total = await count_journal_entries_by_user(wallet.wallet.user)
return await get_journal_entries_by_user(wallet.wallet.user, limit)
return {
"entries": entries,
"total": total,
"limit": limit,
"offset": offset,
"has_next": (offset + limit) < total,
"has_prev": offset > 0,
}
@castle_api_router.get("/api/v1/entries/pending")