""" Router "calendar" provides: - listing calendars - finding calendars by name prefix - getting calendar events by calendar name prefix """ from typing import Iterator from fastapi import APIRouter, Depends from ..dav_calendar import CalEvent, DavCalendar from ._common import CalendarNameLister, PrefixFinder, PrefixUnique router = APIRouter(prefix="/calendar", tags=["calendar"]) calendar_lister = CalendarNameLister() calendar_finder = PrefixFinder(calendar_lister) calendar_unique = PrefixUnique(calendar_finder) @router.get("/list", response_model=list[str]) async def list_calendars( names: Iterator[str] = Depends(calendar_lister), ) -> list[str]: return list(names) @router.get("/find/{prefix}", response_model=list[str]) async def find_calendars( names: Iterator[str] = Depends(calendar_finder), ) -> list[str]: return list(names) @router.get("/get/{prefix}", response_model=list[CalEvent]) async def get_calendar( name: str = Depends(calendar_unique), ) -> list[CalEvent]: return list(await DavCalendar(name).events)