ovdashboard/api/ovdashboard_api/routers/v1/calendar.py

60 lines
1.4 KiB
Python

"""
Router "calendar" provides:
- listing calendars
- finding calendars by name prefix
- getting calendar events by calendar name prefix
"""
from logging import getLogger
from typing import Iterator
from fastapi import APIRouter, Depends
from ...config import CalendarUIConfig, Config
from ...dav_calendar import CalEvent, DavCalendar
from ._common import CalendarNameLister, PrefixFinder, PrefixUnique
_logger = getLogger(__name__)
router = APIRouter(prefix="/calendar", tags=["calendar"])
calendar_lister = CalendarNameLister()
calendar_finder = PrefixFinder(calendar_lister)
calendar_unique = PrefixUnique(calendar_finder)
@router.on_event("startup")
async def start_router() -> None:
_logger.debug(f"{router.prefix} router starting.")
@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)
@router.get(
"/config",
response_model=CalendarUIConfig,
)
async def get_ui_config(
cfg: Config = Depends(Config.get),
) -> CalendarUIConfig:
return cfg.calendar