From 5b75d4f262e44d08e66b6e741b1f85030ffb93c6 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 25 Nov 2022 19:18:14 +0000 Subject: [PATCH] added back crud --- lnbits/extensions/satspay/crud.py | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py index 113b0cb4..3d2b7e98 100644 --- a/lnbits/extensions/satspay/crud.py +++ b/lnbits/extensions/satspay/crud.py @@ -129,6 +129,54 @@ async def check_address_balance(charge_id: str) -> Optional[Charges]: ################## SETTINGS ################### +async def save_theme(data: SatsPayThemes, css_id: str = None): + # insert or update + if css_id: + await db.execute( + """ + UPDATE satspay.themes SET custom_css = ?, title = ? WHERE css_id = ? + """, + (data.custom_css, data.title, css_id), + ) + else: + css_id = urlsafe_short_hash() + await db.execute( + """ + INSERT INTO satspay.themes ( + css_id, + title, + user, + custom_css + ) + VALUES (?, ?, ?, ?) + """, + ( + css_id, + data.title, + data.user, + data.custom_css, + ), + ) + return await get_theme(css_id) + + +async def get_theme(css_id: str) -> SatsPayThemes: + row = await db.fetchone("SELECT * FROM satspay.themes WHERE css_id = ?", (css_id,)) + return SatsPayThemes.from_row(row) if row else None + + +async def get_themes(user_id: str) -> List[SatsPayThemes]: + rows = await db.fetchall( + """SELECT * FROM satspay.themes WHERE "user" = ? ORDER BY "timestamp" DESC """, + (user_id,), + ) + return await get_config(row.user) + + + +################## SETTINGS ################### + + async def save_theme(data: SatsPayThemes, css_id: str = None): # insert or update if css_id: