mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-11 04:52:34 +02:00
Add donation getter endpoint
This commit is contained in:
@@ -161,6 +161,14 @@ async def get_service(service_id: int) -> Optional[Service]:
|
|||||||
return Service.from_row(row) if row else None
|
return Service.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
|
async def get_services(wallet_id: str) -> Optional[list]:
|
||||||
|
rows = await db.fetchall(
|
||||||
|
"SELECT * FROM Services WHERE wallet = ?",
|
||||||
|
(wallet_id,)
|
||||||
|
)
|
||||||
|
return [Service.from_row(row) for row in rows] if rows else None
|
||||||
|
|
||||||
|
|
||||||
async def authenticate_service(service_id, code, redirect_uri):
|
async def authenticate_service(service_id, code, redirect_uri):
|
||||||
# The API token is passed in the querystring as 'code'
|
# The API token is passed in the querystring as 'code'
|
||||||
service = await get_service(service_id)
|
service = await get_service(service_id)
|
||||||
@@ -214,6 +222,18 @@ async def get_donation(donation_id: str) -> Optional[Donation]:
|
|||||||
return Donation.from_row(row) if row else None
|
return Donation.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
|
async def get_donations(wallet_id: str) -> Optional[list]:
|
||||||
|
services = await get_services(wallet_id)
|
||||||
|
service_ids = [service.id for service in services]
|
||||||
|
rows = []
|
||||||
|
for service_id in service_ids:
|
||||||
|
rows.append(await db.fetchall(
|
||||||
|
"SELECT * FROM Donations WHERE service = ?",
|
||||||
|
(service_id,)
|
||||||
|
))
|
||||||
|
return [Donation.from_row(row) for row in rows] if rows else None
|
||||||
|
|
||||||
|
|
||||||
async def delete_donation(donation_id: str) -> None:
|
async def delete_donation(donation_id: str) -> None:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"DELETE FROM Donations WHERE id = ?",
|
"DELETE FROM Donations WHERE id = ?",
|
||||||
|
@@ -2,13 +2,14 @@ from quart import g, redirect, request, jsonify
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from lnbits.decorators import api_validate_post_request, api_check_wallet_key
|
from lnbits.decorators import api_validate_post_request, api_check_wallet_key
|
||||||
from lnbits.core.crud import get_wallet
|
from lnbits.core.crud import get_wallet, get_user
|
||||||
|
|
||||||
from . import twitchalerts_ext
|
from . import twitchalerts_ext
|
||||||
from .crud import (
|
from .crud import (
|
||||||
get_charge_details,
|
get_charge_details,
|
||||||
create_donation,
|
create_donation,
|
||||||
post_donation,
|
post_donation,
|
||||||
|
get_donations,
|
||||||
create_service,
|
create_service,
|
||||||
get_service,
|
get_service,
|
||||||
authenticate_service
|
authenticate_service
|
||||||
@@ -142,3 +143,15 @@ async def api_post_donation():
|
|||||||
jsonify({"message": "Not a paid charge!"}),
|
jsonify({"message": "Not a paid charge!"}),
|
||||||
HTTPStatus.BAD_REQUEST
|
HTTPStatus.BAD_REQUEST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@twitchalerts_ext.route("/api/v1/donations", methods=["GET"])
|
||||||
|
@api_check_wallet_key("invoice")
|
||||||
|
async def api_get_donations():
|
||||||
|
wallet_ids = (await get_user(g.wallet.user)).wallet_ids
|
||||||
|
return (
|
||||||
|
jsonify([
|
||||||
|
donation._asdict() for donation in await get_donations(wallet_ids)
|
||||||
|
]),
|
||||||
|
HTTPStatus.OK,
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user