GET user/next_door

This commit is contained in:
Jörn-Michael Miehe 2023-09-15 16:54:45 +00:00
parent 41368c7191
commit 6bd8f66527

View file

@ -1,10 +1,12 @@
from datetime import datetime
from fastapi import APIRouter, Depends, HTTPException, status from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.responses import StreamingResponse from fastapi.responses import StreamingResponse
from PIL import Image from PIL import Image
from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config
from ..core.depends import get_day_image from ..core.depends import get_all_event_days, get_day_image
from ..core.helpers import api_return_image, load_image from ..core.helpers import EventDays, api_return_image, load_image
from ._security import user_can_view_day, user_is_admin from ._security import user_can_view_day, user_is_admin
router = APIRouter(prefix="/user", tags=["user"]) router = APIRouter(prefix="/user", tags=["user"])
@ -52,3 +54,20 @@ async def get_doors(
""" """
return [door for door in cal_cfg.doors if await user_can_view_day(door.day)] return [door for door in cal_cfg.doors if await user_can_view_day(door.day)]
@router.get("/next_door")
async def get_next_door(
event_days: EventDays = Depends(get_all_event_days),
) -> int | None:
"""
Zeit in ms, bis das nächste Türchen öffnet
"""
if event_days.next is None:
return None
dt = datetime.combine(event_days.next, datetime.min.time())
td = dt - datetime.now()
return int(td.total_seconds() * 1000)