Skip to content

Commit 7f7f4fb

Browse files
committed
fixed
1 parent 61b0d2d commit 7f7f4fb

6 files changed

Lines changed: 283 additions & 258 deletions

File tree

__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import asyncio
22

33
from fastapi import APIRouter
4-
from lnbits.db import Database
54
from loguru import logger
65

6+
from .crud import db
77
from .tasks import wait_for_paid_invoices
88
from .views import example_ext_generic
99
from .views_api import example_ext_api
1010

11-
db = Database("ext_example")
12-
13-
scheduled_tasks: list[asyncio.Task] = []
14-
1511
example_ext: APIRouter = APIRouter(prefix="/example", tags=["example"])
1612
example_ext.include_router(example_ext_generic)
1713
example_ext.include_router(example_ext_api)
@@ -23,6 +19,8 @@
2319
}
2420
]
2521

22+
scheduled_tasks: list[asyncio.Task] = []
23+
2624

2725
def example_stop():
2826
for task in scheduled_tasks:
@@ -37,3 +35,12 @@ def example_start():
3735

3836
task = create_permanent_unique_task("ext_testing", wait_for_paid_invoices)
3937
scheduled_tasks.append(task)
38+
39+
40+
__all__ = [
41+
"db",
42+
"example_ext",
43+
"example_static_files",
44+
"example_start",
45+
"example_stop",
46+
]

crud.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# crud.py is for communication with your extensions database
22

33
# add your dependencies here
4+
# from .models import createExample, Example
5+
from lnbits.db import Database
6+
7+
db = Database("ext_example")
48

59
# add your fnctions here
10+
11+
# async def create_a_record(data: Example) -> createExample:
12+
# example_id = urlsafe_short_hash()
13+
# example = Example(id=example_id, **data.dict())
14+
# await db.insert("example.example", example)
15+
# return example
16+
17+
18+
# async def get_a_record(example_id: str) -> Optional[Example]:
19+
# return await db.fetchone(
20+
# "SELECT * FROM example.example WHERE id = :id", {"id": example_id}, Example
21+
# )

models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
class Example(BaseModel):
55
id: str
66
wallet: str
7+
8+
9+
class CreateExample(BaseModel):
10+
wallet: str

static/js/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ window.app = Vue.createApp({
2222
tab: 'frameworks',
2323
framworktab: 'fastapi',
2424
usefultab: 'magicalg',
25-
vettedData: ''
25+
vettedData: '',
26+
baseUrl: window.location.origin
2627
}
2728
},
2829
// Where functions live
@@ -36,7 +37,7 @@ window.app = Vue.createApp({
3637
data
3738
)
3839
.then(response => {
39-
this.exampleData = response.data.map(mapObject) // Often whats returned is mapped onto some model
40+
this.exampleData.push(mapObject(response.data)) // Often whats returned is mapped onto some model
4041
})
4142
// Error will be passed to the frontend
4243
.catch(LNbits.utils.notifyApiError)

0 commit comments

Comments
 (0)