From dd1dea90c1e716603539085ae34aa1e1c0aa81e5 Mon Sep 17 00:00:00 2001 From: Arc Date: Tue, 19 Nov 2024 00:57:27 +0000 Subject: [PATCH] quickfix --- crud.py | 10 +++++----- migrations.py | 2 +- models.py | 8 ++++++-- static/js/index.js | 1 + views_api.py | 4 +--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crud.py b/crud.py index bef2895..3ba8392 100644 --- a/crud.py +++ b/crud.py @@ -3,16 +3,17 @@ from typing import List, Optional, Union 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") -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) - return data + return MyExtension(**data.dict()) 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): wallet_ids = [wallet_ids] q = ",".join([f"'{w}'" for w in wallet_ids]) - logger.debug(q) return await db.fetchall( f"SELECT * FROM myextension.maintable WHERE wallet IN ({q}) ORDER BY id", model=MyExtension, diff --git a/migrations.py b/migrations.py index 284d901..9fb142b 100644 --- a/migrations.py +++ b/migrations.py @@ -10,7 +10,7 @@ async def m001_initial(db): await db.execute( """ CREATE TABLE myextension.maintable ( - id TEXT PRIMARY KEY, + id TEXT PRIMARY KEY NOT NULL, wallet TEXT NOT NULL, name TEXT NOT NULL, total INTEGER DEFAULT 0, diff --git a/models.py b/models.py index 2161e4f..e836524 100644 --- a/models.py +++ b/models.py @@ -1,12 +1,16 @@ # Description: Pydantic data models dictate what is passed between frontend and backend. +from typing import Optional + from pydantic import BaseModel class CreateMyExtensionData(BaseModel): + id: Optional[str] = "" name: str lnurlpayamount: int lnurlwithdrawamount: int + wallet: str total: int = 0 @@ -17,8 +21,8 @@ class MyExtension(BaseModel): lnurlwithdrawamount: int wallet: str total: int - lnurlpay: str = "" - lnurlwithdraw: str = "" + lnurlpay: Optional[str] = "" + lnurlwithdraw: Optional[str] = "" class CreatePayment(BaseModel): diff --git a/static/js/index.js b/static/js/index.js index e7fc8dd..b6bd46a 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -95,6 +95,7 @@ window.app = Vue.createApp({ this.formDialog.show = true }, async createMyExtension(wallet, data) { + data.wallet = wallet.id await LNbits.api .request('POST', '/myextension/api/v1/myex', wallet.adminkey, data) .then(response => { diff --git a/views_api.py b/views_api.py index 58ff032..4715c5f 100644 --- a/views_api.py +++ b/views_api.py @@ -7,7 +7,6 @@ from lnbits.core.crud import get_user from lnbits.core.models import WalletTypeInfo from lnbits.core.services import create_invoice from lnbits.decorators import require_admin_key, require_invoice_key -from lnbits.helpers import urlsafe_short_hash from starlette.exceptions import HTTPException from .crud import ( @@ -77,8 +76,7 @@ async def api_myextension_create( data: CreateMyExtensionData, wallet: WalletTypeInfo = Depends(require_admin_key), ) -> MyExtension: - myex = MyExtension(**data.dict(), wallet=wallet.wallet.id, id=urlsafe_short_hash()) - myex = await create_myextension(myex) + myex = await create_myextension(data) # Populate lnurlpay and lnurlwithdraw. # Withoutthe lnurl stuff this wouldnt be needed.