ovdashboard/api/ovdashboard_api/routers/calendar.py

34 lines
867 B
Python
Raw Normal View History

2022-09-03 02:00:07 +00:00
from typing import Iterator
2022-09-04 14:14:22 +00:00
from fastapi import APIRouter, Depends
2022-09-02 19:21:15 +00:00
2022-09-04 18:48:46 +00:00
from ..dav_calendar import CalEvent, DavCalendar
2022-09-04 14:14:22 +00:00
from ._common import CalendarNameLister, PrefixFinder, PrefixUnique
2022-09-02 19:21:15 +00:00
router = APIRouter(prefix="/calendar", tags=["calendar"])
_lister = CalendarNameLister()
_finder = PrefixFinder(_lister)
2022-09-04 14:14:22 +00:00
_unique = PrefixUnique(_finder)
2022-09-03 02:00:07 +00:00
@router.get("/list", response_model=list[str])
async def list_calendars(
2022-09-04 14:14:22 +00:00
names: Iterator[str] = Depends(_lister),
2022-09-03 02:00:07 +00:00
) -> list[str]:
2022-09-04 14:14:22 +00:00
return list(names)
2022-09-03 02:00:07 +00:00
@router.get("/find/{prefix}", response_model=list[str])
async def find_calendars(
2022-09-04 14:14:22 +00:00
names: Iterator[str] = Depends(_finder),
2022-09-03 02:00:07 +00:00
) -> list[str]:
2022-09-04 14:14:22 +00:00
return list(names)
2022-09-03 02:00:07 +00:00
2022-09-04 14:14:22 +00:00
@router.get("/get/{prefix}", response_model=list[CalEvent])
2022-09-03 02:00:07 +00:00
async def get_calendar(
2022-09-04 14:14:22 +00:00
name: Iterator[str] = Depends(_unique),
2022-09-04 14:14:22 +00:00
) -> list[CalEvent]:
2022-09-04 18:48:46 +00:00
return list(await DavCalendar(name).events)