-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews_api.py
67 lines (53 loc) · 1.9 KB
/
views_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from http import HTTPStatus
from fastapi import APIRouter, Depends, HTTPException
from lnbits.core.crud import get_user
from lnbits.core.models import WalletTypeInfo
from lnbits.decorators import (
require_admin_key,
require_invoice_key,
)
from .crud import (
create_lnpos,
delete_lnpos,
get_lnpos,
get_lnposs,
update_lnpos,
)
from .models import CreateLnpos
lnpos_api_router = APIRouter()
@lnpos_api_router.post("/api/v1", dependencies=[Depends(require_admin_key)])
async def api_lnpos_create(data: CreateLnpos):
return await create_lnpos(data)
@lnpos_api_router.put("/api/v1/{lnpos_id}", dependencies=[Depends(require_admin_key)])
async def api_lnpos_update(data: CreateLnpos, lnpos_id: str):
lnpos = await get_lnpos(lnpos_id)
if not lnpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="lnpos does not exist"
)
for field, value in data.dict().items():
setattr(lnpos, field, value)
return await update_lnpos(lnpos)
@lnpos_api_router.get("/api/v1")
async def api_lnposs_get(wallet: WalletTypeInfo = Depends(require_invoice_key)):
user = await get_user(wallet.wallet.user)
assert user, "Lnpos cannot retrieve user"
return await get_lnposs(user.wallet_ids)
@lnpos_api_router.get("/api/v1/{lnpos_id}", dependencies=[Depends(require_invoice_key)])
async def api_lnpos_get(lnpos_id: str):
lnpos = await get_lnpos(lnpos_id)
if not lnpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="LNPoS does not exist"
)
return lnpos
@lnpos_api_router.delete(
"/api/v1/{lnpos_id}", dependencies=[Depends(require_admin_key)]
)
async def api_lnpos_delete(lnpos_id: str):
lnpos = await get_lnpos(lnpos_id)
if not lnpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="LNPoS does not exist."
)
await delete_lnpos(lnpos_id)