33 lines
867 B
Python
33 lines
867 B
Python
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"])
|
|
|
|
_lister = CalendarNameLister()
|
|
_finder = PrefixFinder(_lister)
|
|
_unique = PrefixUnique(_finder)
|
|
|
|
|
|
@router.get("/list", response_model=list[str])
|
|
async def list_calendars(
|
|
names: Iterator[str] = Depends(_lister),
|
|
) -> list[str]:
|
|
return list(names)
|
|
|
|
|
|
@router.get("/find/{prefix}", response_model=list[str])
|
|
async def find_calendars(
|
|
names: Iterator[str] = Depends(_finder),
|
|
) -> list[str]:
|
|
return list(names)
|
|
|
|
|
|
@router.get("/get/{prefix}", response_model=list[CalEvent])
|
|
async def get_calendar(
|
|
name: Iterator[str] = Depends(_unique),
|
|
) -> list[CalEvent]:
|
|
return list(await DavCalendar(name).events)
|