Settings now save and load and have an insert or delete for new / existing settings

This commit is contained in:
Black Coffee 2022-10-24 15:53:43 +01:00 committed by Vlad Stan
parent 4e9132ec04
commit 220dc699cf
4 changed files with 48 additions and 1 deletions

View File

@ -102,6 +102,19 @@ async def get_charges(user: str) -> List[Charges]:
)
return [Charges.from_row(row) for row in rows]
async def get_settings(user: str) -> SatsPaySettings:
row = await db.fetchone(
"""SELECT * FROM satspay.settings WHERE "user" = ?""",
(user,),
)
logger.debug('Settings data')
logger.debug(row)
if row:
return SatsPaySettings.from_row(row)
else:
return None
async def delete_charge(charge_id: str) -> None:
await db.execute("DELETE FROM satspay.charges WHERE id = ?", (charge_id,))

View File

@ -74,3 +74,7 @@ class Charges(BaseModel):
return self.webhook and self.paid and self.config.webhook_success == False
class SatsPaySettings(BaseModel):
custom_css: str = Query(None)
@classmethod
def from_row(cls, row: Row) -> "SatsPaySettings":
return cls(**dict(row))

View File

@ -9,7 +9,7 @@
>New charge
</q-btn>
<q-btn unelevated color="primary" @click="formDialogSettings.show = true"
<q-btn unelevated color="primary" @click="getSettings();formDialogSettings.show = true"
>SatsPay settings
</q-btn>
@ -442,6 +442,7 @@
mixins: [windowMixin],
data: function () {
return {
settings: {},
filter: '',
balance: null,
walletLinks: [],
@ -622,6 +623,21 @@
LNbits.utils.notifyApiError(error)
}
},
getSettings: async function () {
try {
const {data} = await LNbits.api.request(
'GET',
'/satspay/api/v1/settings',
this.g.user.wallets[0].inkey
)
console.log('Settings data', data)
this.formDialogSettings.data = data
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
sendFormDataSettings: function () {
const wallet = this.g.user.wallets[0].inkey
const data = this.formDialogSettings.data
@ -700,6 +716,7 @@
}
},
saveSettings: async function (wallet, data) {
console.log('wallet', wallet)
try {
const resp = await LNbits.api.request(
'POST',
@ -768,6 +785,7 @@
}
},
created: async function () {
await this.getSettings()
await this.getCharges()
await this.getWalletConfig()
await this.getWalletLinks()

View File

@ -22,6 +22,7 @@ from .crud import (
get_charges,
update_charge,
save_settings,
get_settings,
)
from .helpers import call_webhook, public_charge
from .helpers import compact_charge
@ -153,3 +154,14 @@ async def api_settings_save(
logger.debug(wallet.wallet.user)
await save_settings(user=wallet.wallet.user, data=data)
return True
@satspay_ext.get("/api/v1/settings")
async def api_settings_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)):
logger.debug('HERHEHRHEHRHEHR')
try:
return await get_settings(wallet.wallet.user)
except HTTPException:
logger.error('Error loading satspay settings')
logger.error(HTTPException)
return ""