From 6bd8f665273b2702cd399cf788e04e8c37fd2e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Fri, 15 Sep 2023 16:54:45 +0000 Subject: [PATCH] GET user/next_door --- api/advent22_api/routers/user.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/api/advent22_api/routers/user.py b/api/advent22_api/routers/user.py index daf511d..bb0f992 100644 --- a/api/advent22_api/routers/user.py +++ b/api/advent22_api/routers/user.py @@ -1,10 +1,12 @@ +from datetime import datetime + from fastapi import APIRouter, Depends, HTTPException, status from fastapi.responses import StreamingResponse from PIL import Image from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config -from ..core.depends import get_day_image -from ..core.helpers import api_return_image, load_image +from ..core.depends import get_all_event_days, get_day_image +from ..core.helpers import EventDays, api_return_image, load_image from ._security import user_can_view_day, user_is_admin 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)] + + +@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)