""" Router "calendar" provides: - listing calendars - finding calendars by name prefix - getting calendar events by calendar name prefix """ import logging from fastapi import APIRouter, Depends from ...core.caldav import CalDAV, CalEvent from ...core.config import CalendarUIConfig, Config from ._common import LM_CALENDAR, get_config _logger = logging.getLogger(__name__) router = APIRouter(prefix="/calendar", tags=["calendar"]) @router.on_event("startup") async def start_router() -> None: _logger.debug(f"{router.prefix} router starting.") @router.get( "/list", responses=LM_CALENDAR.lister.responses, ) async def list_all_calendars( names: list[str] = Depends(LM_CALENDAR.lister.func), ) -> list[str]: return names @router.get( "/find/{prefix}", responses=LM_CALENDAR.filter.responses, ) async def find_calendars( names: list[str] = Depends(LM_CALENDAR.filter.func), ) -> list[str]: return names @router.get( "/get/{prefix}", responses=LM_CALENDAR.getter.responses, ) async def get_calendar( name: str = Depends(LM_CALENDAR.getter.func), cfg: Config = Depends(get_config), ) -> list[CalEvent]: return await CalDAV.get_events(name, cfg) @router.get("/config") async def get_ui_config( cfg: Config = Depends(get_config), ) -> CalendarUIConfig: return cfg.calendar