-
Notifications
You must be signed in to change notification settings - Fork 4
/
views_api_themes.py
50 lines (38 loc) · 1.36 KB
/
views_api_themes.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
from http import HTTPStatus
from fastapi import APIRouter, Depends, HTTPException
from lnbits.core.models import User
from lnbits.decorators import check_admin
from .crud import create_theme, delete_theme, get_theme, get_themes, update_theme
from .models import CreateSatsPayTheme, SatsPayTheme
satspay_theme_router = APIRouter()
@satspay_theme_router.post("/api/v1/themes")
async def api_themes_create(
data: CreateSatsPayTheme,
user: User = Depends(check_admin),
) -> SatsPayTheme:
return await create_theme(data=data, user_id=user.id)
@satspay_theme_router.post("/api/v1/themes/{css_id}")
async def api_themes_save(
css_id: str,
data: CreateSatsPayTheme,
user: User = Depends(check_admin),
) -> SatsPayTheme:
theme = SatsPayTheme(
css_id=css_id,
user=user.id,
**data.dict(),
)
return await update_theme(theme)
@satspay_theme_router.get("/api/v1/themes")
async def api_get_themes(user: User = Depends(check_admin)) -> list[SatsPayTheme]:
return await get_themes(user.id)
@satspay_theme_router.delete(
"/api/v1/themes/{theme_id}", dependencies=[Depends(check_admin)]
)
async def api_theme_delete(theme_id):
theme = await get_theme(theme_id)
if not theme:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Theme does not exist."
)
await delete_theme(theme_id)