Merge remote-tracking branch 'arcbtc/FastAPI' into benarcfastapi

This commit is contained in:
Ben Arc 2021-08-20 20:12:07 +01:00
commit bdbdc1601b
5 changed files with 37 additions and 41 deletions

View file

@ -1,3 +1,4 @@
from pydantic.types import constr
import trio
import json
import httpx
@ -5,15 +6,13 @@ import hashlib
from urllib.parse import urlparse, urlunparse, urlencode, parse_qs, ParseResult
from quart import g, current_app, make_response, url_for
from fastapi import FastAPI
from fastapi import Query
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from http import HTTPStatus
from binascii import unhexlify
from typing import Dict, Union
from typing import Dict, List, Optional, Union
from lnbits import bolt11, lnurl
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
@ -95,15 +94,7 @@ async def api_payments():
# async def api_payments_create_invoice(amount: List[str] = Query([type: str = Query(None)])):
class Memo(BaseModel):
type: str
empty: bool
required: bool
excludes: bool
excludes: bool = Query("description_hash")
async def api_payments_create_invoice(amount: int = Query(...), memo: Memo ):
async def api_payments_create_invoice(memo: Union[None, constr(min_length=1)], amount: int):
if "description_hash" in g.data:
description_hash = unhexlify(g.data["description_hash"])
memo = ""

View file

@ -5,6 +5,8 @@ from lnbits.core.crud import get_user, get_wallet
from lnbits.core.services import create_invoice, check_invoice_status
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from fastapi.encoders import jsonable_encoder
from fastapi import Query
from pydantic import BaseModel
from . import events_ext
from .crud import (
@ -41,14 +43,14 @@ async def api_events():
)
class CreateData(BaseModel):
wallet: str = Query(...),
name: str = Query(...),
info: str = Query(...),
closing_date: str = Query(...),
event_start_date: str = Query(...),
event_end_date: str = Query(...),
amount_tickets: int = Query(..., ge=0),
price_per_ticket: int = Query(..., ge=0),
wallet: str = Query(...)
name: str = Query(...)
info: str = Query(...)
closing_date: str = Query(...)
event_start_date: str = Query(...)
event_end_date: str = Query(...)
amount_tickets: int = Query(..., ge=0)
price_per_ticket: int = Query(..., ge=0)
@events_ext.post("/api/v1/events")
@events_ext.put("/api/v1/events/<event_id>")
@ -100,7 +102,7 @@ async def api_tickets():
)
class CreateTicketData(BaseModel):
name: str = Query(...),
name: str = Query(...)
email: str
@events_ext.post("/api/v1/tickets/<event_id>/<sats>")

View file

@ -4,6 +4,9 @@ import base64
from lnbits.core.crud import get_wallet
from lnbits.core.services import create_invoice, check_invoice_status
import json
from typing import Optional
from pydantic import BaseModel
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
import httpx
@ -74,16 +77,16 @@ async def api_check_credentials_check(juke_id):
class CreateData(BaseModel):
user: str = None,
title: str = None,
wallet: str = None,
sp_user: str = None,
sp_secret: str = None,
sp_access_token: Optional[str] = None,
sp_refresh_token: Optional[str] = None,
sp_device: Optional[str] = None,
sp_playlists: Optional[str] = None,
price: Optional[str] = None,
user: str = None
title: str = None
wallet: str = None
sp_user: str = None
sp_secret: str = None
sp_access_token: Optional[str] = None
sp_refresh_token: Optional[str] = None
sp_device: Optional[str] = None
sp_playlists: Optional[str] = None
price: Optional[str] = None
@jukebox_ext.post("/api/v1/jukebox/")
@jukebox_ext.put("/api/v1/jukebox/<juke_id>")

View file

@ -27,10 +27,10 @@ async def api_paywalls():
class CreateData(BaseModel):
url: Optional[str] = Query(...),
memo: Optional[str] = Query(...),
description: str = Query(None),
amount: int = Query(None),
url: Optional[str] = Query(...)
memo: Optional[str] = Query(...)
description: str = Query(None)
amount: int = Query(None)
remembers: bool = Query(None)
@paywall_ext.post("/api/v1/paywalls")

View file

@ -68,11 +68,11 @@ async def api_link_retrieve(link_id):
return jsonable_encoder({**link, **{"lnurl": link.lnurl}}), HTTPStatus.OK
class CreateData(BaseModel):
title: str = Query(...),
min_withdrawable: int = Query(..., ge=1),
max_withdrawable: int = Query(..., ge=1),
uses: int = Query(..., ge=1),
wait_time: int = Query(..., ge=1),
title: str = Query(...)
min_withdrawable: int = Query(..., ge=1)
max_withdrawable: int = Query(..., ge=1)
uses: int = Query(..., ge=1)
wait_time: int = Query(..., ge=1)
is_unique: bool
@withdraw_ext.post("/api/v1/links")