mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-12-25 22:02:59 +00:00
Jörn-Michael Miehe
af00dafb6c
apparently, a @staticmethod that Depends on another @staticmethod in the same class is bad
48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends
|
|
from fastapi.responses import StreamingResponse
|
|
|
|
from ..core.calendar_config import CalendarConfig, DoorsSaved
|
|
from ..core.image_helpers import api_return_image, load_image
|
|
|
|
router = APIRouter(prefix="/general", tags=["general"])
|
|
|
|
|
|
@router.get(
|
|
"/background",
|
|
response_class=StreamingResponse,
|
|
)
|
|
async def get_image_for_day(
|
|
cal_cfg: CalendarConfig = Depends(CalendarConfig.get_calendar_config),
|
|
) -> StreamingResponse:
|
|
"""
|
|
Hintergrundbild laden
|
|
"""
|
|
|
|
return await api_return_image(await load_image(f"files/{cal_cfg.background}"))
|
|
|
|
|
|
@router.get("/doors")
|
|
async def get_doors(
|
|
cal_cfg: CalendarConfig = Depends(CalendarConfig.get_calendar_config),
|
|
) -> DoorsSaved:
|
|
"""
|
|
Türchen lesen
|
|
"""
|
|
|
|
return cal_cfg.doors
|
|
|
|
|
|
@router.put("/doors")
|
|
async def put_doors(
|
|
doors: DoorsSaved,
|
|
cal_cfg: CalendarConfig = Depends(CalendarConfig.get_calendar_config),
|
|
) -> None:
|
|
"""
|
|
Türchen setzen
|
|
"""
|
|
|
|
cal_cfg.doors = sorted(
|
|
doors,
|
|
key=lambda door: door.day,
|
|
)
|
|
await cal_cfg.set_calendar_config()
|