Merge pull request #402 from arcbtc/FastAPI

Added some IF EXISTS
This commit is contained in:
Arc 2021-11-09 15:23:17 +00:00 committed by GitHub
commit 3611c9f7c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 22 deletions

View File

@ -4,7 +4,7 @@ from sqlalchemy.exc import OperationalError # type: ignore
async def m000_create_migrations_table(db):
await db.execute(
"""
CREATE TABLE dbversions (
CREATE TABLE IF NOT EXISTS dbversions (
db TEXT PRIMARY KEY,
version INT NOT NULL
)
@ -18,7 +18,7 @@ async def m001_initial(db):
"""
await db.execute(
"""
CREATE TABLE accounts (
CREATE TABLE IF NOT EXISTS accounts (
id TEXT PRIMARY KEY,
email TEXT,
pass TEXT
@ -27,7 +27,7 @@ async def m001_initial(db):
)
await db.execute(
"""
CREATE TABLE extensions (
CREATE TABLE IF NOT EXISTS extensions (
"user" TEXT NOT NULL,
extension TEXT NOT NULL,
active BOOLEAN DEFAULT false,
@ -38,7 +38,7 @@ async def m001_initial(db):
)
await db.execute(
"""
CREATE TABLE wallets (
CREATE TABLE IF NOT EXISTS wallets (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
"user" TEXT NOT NULL,
@ -49,7 +49,7 @@ async def m001_initial(db):
)
await db.execute(
f"""
CREATE TABLE apipayments (
CREATE TABLE IF NOT EXISTS apipayments (
payhash TEXT NOT NULL,
amount INTEGER NOT NULL,
fee INTEGER NOT NULL DEFAULT 0,
@ -64,7 +64,7 @@ async def m001_initial(db):
await db.execute(
"""
CREATE VIEW balances AS
CREATE VIEW IF NOT EXISTS balances AS
SELECT wallet, COALESCE(SUM(s), 0) AS balance FROM (
SELECT wallet, SUM(amount) AS s -- incoming
FROM apipayments
@ -144,7 +144,7 @@ async def m004_ensure_fees_are_always_negative(db):
await db.execute("DROP VIEW balances")
await db.execute(
"""
CREATE VIEW balances AS
CREATE VIEW IF NOT EXISTS balances AS
SELECT wallet, COALESCE(SUM(s), 0) AS balance FROM (
SELECT wallet, SUM(amount) AS s -- incoming
FROM apipayments
@ -168,7 +168,7 @@ async def m005_balance_check_balance_notify(db):
await db.execute(
"""
CREATE TABLE balance_check (
CREATE TABLE IF NOT EXISTS balance_check (
wallet TEXT NOT NULL REFERENCES wallets (id),
service TEXT NOT NULL,
url TEXT NOT NULL,
@ -180,7 +180,7 @@ async def m005_balance_check_balance_notify(db):
await db.execute(
"""
CREATE TABLE balance_notify (
CREATE TABLE IF NOT EXISTS balance_notify (
wallet TEXT NOT NULL REFERENCES wallets (id),
url TEXT NOT NULL,

View File

@ -88,7 +88,7 @@ async def m003_changed(db):
await db.execute(
"""
CREATE TABLE lnticket.form (
CREATE TABLE IF NOT EXISTS lnticket.form (
id TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
name TEXT NOT NULL,

View File

@ -1,4 +1,3 @@
import json
from http import HTTPStatus
from typing import Optional
@ -10,7 +9,6 @@ from starlette.requests import Request
from starlette.responses import HTMLResponse # type: ignore
from lnbits.decorators import WalletTypeInfo, get_key_type
from lnbits.requestvars import g
from lnbits.utils.exchange_rates import currencies
from . import offlineshop_ext
@ -27,11 +25,10 @@ from .models import ShopCounter
@offlineshop_ext.get("/api/v1/currencies")
async def api_list_currencies_available():
return json.dumps(list(currencies.keys()))
return list(currencies.keys())
@offlineshop_ext.get("/api/v1/offlineshop")
# @api_check_wallet_key("invoice")
async def api_shop_from_wallet(
r: Request, wallet: WalletTypeInfo = Depends(get_key_type)
):
@ -60,7 +57,6 @@ class CreateItemsData(BaseModel):
@offlineshop_ext.post("/api/v1/offlineshop/items")
@offlineshop_ext.put("/api/v1/offlineshop/items/{item_id}")
# @api_check_wallet_key("invoice")
async def api_add_or_update_item(
data: CreateItemsData, item_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
):
@ -83,7 +79,6 @@ async def api_add_or_update_item(
@offlineshop_ext.delete("/api/v1/offlineshop/items/{item_id}")
# @api_check_wallet_key("invoice")
async def api_delete_item(item_id, wallet: WalletTypeInfo = Depends(get_key_type)):
shop = await get_or_create_shop_by_wallet(wallet.wallet.id)
await delete_item_from_shop(shop.id, item_id)
@ -96,7 +91,6 @@ class CreateMethodData(BaseModel):
@offlineshop_ext.put("/api/v1/offlineshop/method")
# @api_check_wallet_key("invoice")
async def api_set_method(
data: CreateMethodData, wallet: WalletTypeInfo = Depends(get_key_type)
):

View File

@ -38,7 +38,7 @@ async def on_invoice_paid(payment: Payment) -> None:
domain = await get_domain(subdomain.domain)
### Create subdomain
cf_response = cloudflare_create_subdomain(
cf_response = await cloudflare_create_subdomain(
domain=domain,
subdomain=subdomain.subdomain,
record_type=subdomain.record_type,

View File

@ -417,7 +417,7 @@
LNbits.api
.request(
'DELETE',
'/subdomain/api/v1/subdomains/' + subdomainId,
'/subdomains/api/v1/subdomains/' + subdomainId,
_.findWhere(self.g.user.wallets, {id: subdomains.wallet}).inkey
)
.then(function (response) {

View File

@ -124,7 +124,7 @@ async def api_subdomain_make_subdomain(domain_id, data: CreateSubdomain):
ip=data.ip,
)
if cf_response["success"] == True:
cloudflare_deletesubdomain(domain=domain, domain_id=cf_response["result"]["id"])
await cloudflare_deletesubdomain(domain=domain, domain_id=cf_response["result"]["id"])
else:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,

View File

@ -56,7 +56,10 @@ async def get_withdraw_link(link_id: str, num=0) -> Optional[WithdrawLink]:
if not row:
return None
return WithdrawLink(**row) if row else None
link = dict(**row)
link["number"] = num
return WithdrawLink.parse_obj(link)
async def get_withdraw_link_by_hash(unique_hash: str, num=0) -> Optional[WithdrawLink]:
@ -65,7 +68,11 @@ async def get_withdraw_link_by_hash(unique_hash: str, num=0) -> Optional[Withdra
)
if not row:
return None
return WithdrawLink(**row) if row else None
link = dict(**row)
link["number"] = num
return WithdrawLink.parse_obj(link)
async def get_withdraw_links(wallet_ids: Union[str, List[str]]) -> List[WithdrawLink]: