Adds user settings for the Castle extension
Adds functionality to configure the Castle extension, including a wallet ID. This allows administrators to customize the extension's behavior by specifying a dedicated wallet for castle operations.
This commit is contained in:
parent
ceabf96f79
commit
29983cedb7
7 changed files with 199 additions and 2 deletions
32
crud.py
32
crud.py
|
|
@ -8,12 +8,14 @@ from lnbits.helpers import urlsafe_short_hash
|
|||
from .models import (
|
||||
Account,
|
||||
AccountType,
|
||||
CastleSettings,
|
||||
CreateAccount,
|
||||
CreateEntryLine,
|
||||
CreateJournalEntry,
|
||||
EntryLine,
|
||||
JournalEntry,
|
||||
UserBalance,
|
||||
UserCastleSettings,
|
||||
)
|
||||
|
||||
db = Database("ext_castle")
|
||||
|
|
@ -345,3 +347,33 @@ async def get_account_transactions(
|
|||
transactions.append((entry, line))
|
||||
|
||||
return transactions
|
||||
|
||||
|
||||
# ===== SETTINGS =====
|
||||
|
||||
|
||||
async def create_castle_settings(
|
||||
user_id: str, data: CastleSettings
|
||||
) -> CastleSettings:
|
||||
settings = UserCastleSettings(**data.dict(), id=user_id)
|
||||
await db.insert("extension_settings", settings)
|
||||
return settings
|
||||
|
||||
|
||||
async def get_castle_settings(user_id: str) -> Optional[CastleSettings]:
|
||||
return await db.fetchone(
|
||||
"""
|
||||
SELECT * FROM extension_settings
|
||||
WHERE id = :user_id
|
||||
""",
|
||||
{"user_id": user_id},
|
||||
CastleSettings,
|
||||
)
|
||||
|
||||
|
||||
async def update_castle_settings(
|
||||
user_id: str, data: CastleSettings
|
||||
) -> CastleSettings:
|
||||
settings = UserCastleSettings(**data.dict(), id=user_id)
|
||||
await db.update("extension_settings", settings)
|
||||
return settings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue