mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-02 14:09:26 +02:00
feat(tpos): type casting
This commit is contained in:
@@ -24,7 +24,7 @@ def get_tpos(tpos_id: str) -> Optional[TPoS]:
|
|||||||
with open_ext_db("tpos") as db:
|
with open_ext_db("tpos") as db:
|
||||||
row = db.fetchone("SELECT * FROM tposs WHERE id = ?", (tpos_id,))
|
row = db.fetchone("SELECT * FROM tposs WHERE id = ?", (tpos_id,))
|
||||||
|
|
||||||
return TPoS(**row) if row else None
|
return TPoS.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
def get_tposs(wallet_ids: Union[str, List[str]]) -> List[TPoS]:
|
def get_tposs(wallet_ids: Union[str, List[str]]) -> List[TPoS]:
|
||||||
@@ -35,7 +35,7 @@ def get_tposs(wallet_ids: Union[str, List[str]]) -> List[TPoS]:
|
|||||||
q = ",".join(["?"] * len(wallet_ids))
|
q = ",".join(["?"] * len(wallet_ids))
|
||||||
rows = db.fetchall(f"SELECT * FROM tposs WHERE wallet IN ({q})", (*wallet_ids,))
|
rows = db.fetchall(f"SELECT * FROM tposs WHERE wallet IN ({q})", (*wallet_ids,))
|
||||||
|
|
||||||
return [TPoS(**row) for row in rows]
|
return [TPoS.from_row(row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
def delete_tpos(tpos_id: str) -> None:
|
def delete_tpos(tpos_id: str) -> None:
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
from sqlite3 import Row
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
|
|
||||||
@@ -6,3 +7,7 @@ class TPoS(NamedTuple):
|
|||||||
wallet: str
|
wallet: str
|
||||||
name: str
|
name: str
|
||||||
currency: str
|
currency: str
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_row(cls, row: Row) -> "TPoS":
|
||||||
|
return cls(**dict(row))
|
||||||
|
@@ -8,21 +8,18 @@
|
|||||||
group="api"
|
group="api"
|
||||||
dense
|
dense
|
||||||
expand-separator
|
expand-separator
|
||||||
label="List all users TPoS"
|
label="List TPoS"
|
||||||
>
|
>
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code><span class="text-light-blue">GET</span> /tpos/api/v1/tposs</code>
|
<code><span class="text-blue">GET</span> /tpos/api/v1/tposs</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||||
<code>{"X-Api-Key": <invoice_key>}</code><br />
|
<code>{"X-Api-Key": <invoice_key>}</code><br />
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">
|
<h5 class="text-caption q-mt-sm q-mb-none">
|
||||||
Returns 201 CREATED (application/json)
|
Returns 200 OK (application/json)
|
||||||
</h5>
|
</h5>
|
||||||
<code
|
<code>[<tpos_object>, ...]</code>
|
||||||
>{"currency": <string>, "id": <string>, "name":
|
|
||||||
<string>, "wallet": <string>}</code
|
|
||||||
>
|
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.url_root }}tpos/api/v1/tposs -H "X-Api-Key:
|
>curl -X GET {{ request.url_root }}tpos/api/v1/tposs -H "X-Api-Key:
|
||||||
@@ -35,7 +32,7 @@
|
|||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code
|
<code
|
||||||
><span class="text-light-green">POST</span> /tpos/api/v1/tposs</code
|
><span class="text-green">POST</span> /tpos/api/v1/tposs</code
|
||||||
>
|
>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||||
<code>{"X-Api-Key": <invoice_key>}</code><br />
|
<code>{"X-Api-Key": <invoice_key>}</code><br />
|
||||||
@@ -70,12 +67,12 @@
|
|||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code
|
<code
|
||||||
><span class="text-light-green">DELETE</span>
|
><span class="text-pink">DELETE</span>
|
||||||
/tpos/api/v1/tposs/<tpos_id></code
|
/tpos/api/v1/tposs/<tpos_id></code
|
||||||
>
|
>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||||
<code>{"X-Api-Key": <admin_key>}</code><br />
|
<code>{"X-Api-Key": <admin_key>}</code><br />
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Returns 201 NO_CONTENT</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Returns 204 NO CONTENT</h5>
|
||||||
<code></code>
|
<code></code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
|
Reference in New Issue
Block a user