quickfix
This commit is contained in:
parent
2b0281857a
commit
dd1dea90c1
5 changed files with 14 additions and 11 deletions
10
crud.py
10
crud.py
|
|
@ -3,16 +3,17 @@
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from lnbits.db import Database
|
from lnbits.db import Database
|
||||||
from loguru import logger
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
from .models import MyExtension
|
from .models import CreateMyExtensionData, MyExtension
|
||||||
|
|
||||||
db = Database("ext_myextension")
|
db = Database("ext_myextension")
|
||||||
|
|
||||||
|
|
||||||
async def create_myextension(data: MyExtension) -> MyExtension:
|
async def create_myextension(data: CreateMyExtensionData) -> MyExtension:
|
||||||
|
data.id = urlsafe_short_hash()
|
||||||
await db.insert("myextension.maintable", data)
|
await db.insert("myextension.maintable", data)
|
||||||
return data
|
return MyExtension(**data.dict())
|
||||||
|
|
||||||
|
|
||||||
async def get_myextension(myextension_id: str) -> Optional[MyExtension]:
|
async def get_myextension(myextension_id: str) -> Optional[MyExtension]:
|
||||||
|
|
@ -27,7 +28,6 @@ async def get_myextensions(wallet_ids: Union[str, List[str]]) -> List[MyExtensio
|
||||||
if isinstance(wallet_ids, str):
|
if isinstance(wallet_ids, str):
|
||||||
wallet_ids = [wallet_ids]
|
wallet_ids = [wallet_ids]
|
||||||
q = ",".join([f"'{w}'" for w in wallet_ids])
|
q = ",".join([f"'{w}'" for w in wallet_ids])
|
||||||
logger.debug(q)
|
|
||||||
return await db.fetchall(
|
return await db.fetchall(
|
||||||
f"SELECT * FROM myextension.maintable WHERE wallet IN ({q}) ORDER BY id",
|
f"SELECT * FROM myextension.maintable WHERE wallet IN ({q}) ORDER BY id",
|
||||||
model=MyExtension,
|
model=MyExtension,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ async def m001_initial(db):
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE myextension.maintable (
|
CREATE TABLE myextension.maintable (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
wallet TEXT NOT NULL,
|
wallet TEXT NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
total INTEGER DEFAULT 0,
|
total INTEGER DEFAULT 0,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
# Description: Pydantic data models dictate what is passed between frontend and backend.
|
# Description: Pydantic data models dictate what is passed between frontend and backend.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class CreateMyExtensionData(BaseModel):
|
class CreateMyExtensionData(BaseModel):
|
||||||
|
id: Optional[str] = ""
|
||||||
name: str
|
name: str
|
||||||
lnurlpayamount: int
|
lnurlpayamount: int
|
||||||
lnurlwithdrawamount: int
|
lnurlwithdrawamount: int
|
||||||
|
wallet: str
|
||||||
total: int = 0
|
total: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,8 +21,8 @@ class MyExtension(BaseModel):
|
||||||
lnurlwithdrawamount: int
|
lnurlwithdrawamount: int
|
||||||
wallet: str
|
wallet: str
|
||||||
total: int
|
total: int
|
||||||
lnurlpay: str = ""
|
lnurlpay: Optional[str] = ""
|
||||||
lnurlwithdraw: str = ""
|
lnurlwithdraw: Optional[str] = ""
|
||||||
|
|
||||||
|
|
||||||
class CreatePayment(BaseModel):
|
class CreatePayment(BaseModel):
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ window.app = Vue.createApp({
|
||||||
this.formDialog.show = true
|
this.formDialog.show = true
|
||||||
},
|
},
|
||||||
async createMyExtension(wallet, data) {
|
async createMyExtension(wallet, data) {
|
||||||
|
data.wallet = wallet.id
|
||||||
await LNbits.api
|
await LNbits.api
|
||||||
.request('POST', '/myextension/api/v1/myex', wallet.adminkey, data)
|
.request('POST', '/myextension/api/v1/myex', wallet.adminkey, data)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ from lnbits.core.crud import get_user
|
||||||
from lnbits.core.models import WalletTypeInfo
|
from lnbits.core.models import WalletTypeInfo
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.decorators import require_admin_key, require_invoice_key
|
from lnbits.decorators import require_admin_key, require_invoice_key
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from .crud import (
|
from .crud import (
|
||||||
|
|
@ -77,8 +76,7 @@ async def api_myextension_create(
|
||||||
data: CreateMyExtensionData,
|
data: CreateMyExtensionData,
|
||||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||||
) -> MyExtension:
|
) -> MyExtension:
|
||||||
myex = MyExtension(**data.dict(), wallet=wallet.wallet.id, id=urlsafe_short_hash())
|
myex = await create_myextension(data)
|
||||||
myex = await create_myextension(myex)
|
|
||||||
|
|
||||||
# Populate lnurlpay and lnurlwithdraw.
|
# Populate lnurlpay and lnurlwithdraw.
|
||||||
# Withoutthe lnurl stuff this wouldnt be needed.
|
# Withoutthe lnurl stuff this wouldnt be needed.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue