fix: syntax errors

This commit is contained in:
Stefan Stammberger 2021-08-20 20:54:59 +02:00
parent 58a498d9bf
commit 37a7950f0f
No known key found for this signature in database
GPG Key ID: 645FA807E935D9D5
6 changed files with 40 additions and 44 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

@ -17,7 +17,7 @@ from .models import TPoS
@tpos_ext.get("/api/v1/tposs")
@api_check_wallet_key("invoice")
async def api_tposs(all_wallets: boolean = Query(None)):
async def api_tposs(all_wallets: bool = Query(None)):
wallet_ids = [g.wallet.id]
if all_wallets:
wallet_ids = wallet_ids = (await get_user(g.wallet.user)).wallet_ids(await get_user(g.wallet.user)).wallet_ids
@ -60,7 +60,7 @@ async def api_tpos_delete(tpos_id: str):
# @api_validate_post_request(
# schema={"amount": {"type": "integer", "min": 1, "required": True}}
# )
async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str):
async def api_tpos_create_invoice(tpos_id: str, amount: int = Query(..., ge=1)):
tpos = await get_tpos(tpos_id)
if not tpos:
@ -76,7 +76,7 @@ async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str):
except Exception as e:
return {"message": str(e)}, HTTPStatus.INTERNAL_SERVER_ERROR
return {"payment_hash": payment_hash, "payment_request": payment_request}), HTTPStatus.CREATED
return {"payment_hash": payment_hash, "payment_request": payment_request}, HTTPStatus.CREATED
@tpos_ext.get("/api/v1/tposs/{tpos_id}/invoices/{payment_hash}")

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")