Pydantic being quietly pydantic

This commit is contained in:
benarc 2021-10-13 11:20:40 +01:00
parent d5a4dc801f
commit 16f9f1612f
3 changed files with 23 additions and 32 deletions

View File

@ -37,7 +37,7 @@ async def create_copilot(
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
data.copilot_id,
copilot_id,
data.user,
int(data.lnurl_toggle),
data.wallet,

View File

@ -1,38 +1,35 @@
import json
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
from starlette.requests import Request
from fastapi.param_functions import Query
from typing import Optional, Dict
from lnbits.lnurl import encode as lnurl_encode # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore
from sqlite3 import Row
from pydantic import BaseModel
class CreateCopilotData(BaseModel):
id: Optional[str] = None
user: Optional[str] = None
title: Optional[str] = None
lnurl_toggle: Optional[int] = None
wallet: Optional[str] = None
animation1: Optional[str] = None
animation2: Optional[str] = None
animation3: Optional[str] = None
animation1threshold: Optional[int] = None
animation2threshold: Optional[int] = None
animation3threshold: Optional[int] = None
animation1webhook: Optional[str] = None
animation2webhook: Optional[str] = None
animation3webhook: Optional[str] = None
lnurl_title: Optional[str] = None
show_message: Optional[int] = None
show_ack: Optional[int] = None
show_price: Optional[int] = None
amount_made: Optional[int] = None
timestamp: Optional[int] = None
fullscreen_cam: Optional[int] = None
iframe_url: Optional[int] = None
success_url: Optional[str] = None
user: str = Query(None)
title: str = Query(None)
lnurl_toggle: int = Query(None)
wallet: str = Query(None)
animation1: str = Query(None)
animation2: str = Query(None)
animation3: str = Query(None)
animation1threshold: int = Query(None)
animation2threshold: int = Query(None)
animation3threshold: int = Query(None)
animation1webhook: str = Query(None)
animation2webhook: str = Query(None)
animation3webhook: str = Query(None)
lnurl_title: str = Query(None)
show_message: int = Query(None)
show_ack: int = Query(None)
show_price: str = Query(None)
amount_made: int = Query(None)
timestamp: int = Query(None)
fullscreen_cam: int = Query(None)
iframe_url: int = Query(None)
success_url: str = Query(None)
class Copilots(BaseModel):
@ -59,10 +56,6 @@ class Copilots(BaseModel):
fullscreen_cam: int
iframe_url: str
@classmethod
def from_row(cls, row: Row) -> "Copilots":
return cls(**dict(row))
def lnurl(self, req: Request) -> str:
url = req.url_for("copilot.lnurl_response", link_id=self.id)
return lnurl_encode(url)

View File

@ -69,11 +69,9 @@ async def api_copilot_create_or_update(
copilot_id: str = Query(None),
wallet: WalletTypeInfo = Depends(get_key_type),
):
print("cunt")
if not copilot_id:
copilot = await create_copilot(data, inkey=wallet.wallet.inkey)
return copilot, HTTPStatus.CREATED
else:
copilot = await update_copilot(data, copilot_id=copilot_id)