ovdashboard/api/ovdashboard_api/routers/calendar.py
2022-09-05 23:30:06 +02:00

41 lines
1,010 B
Python

"""
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"])
_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)