ovdashboard/api/ovdashboard_api/routers/v1/calendar.py
2023-10-26 17:48:33 +02:00

62 lines
1.3 KiB
Python

"""
Router "calendar" provides:
- listing calendars
- finding calendars by name prefix
- getting calendar events by calendar name prefix
"""
from logging import getLogger
from fastapi import APIRouter, Depends
from ...core.caldav import CalDAV, CalEvent
from ...core.config import CalendarUIConfig, Config, get_config
from ._common import LM_CALENDARS
_logger = getLogger(__name__)
router = APIRouter(prefix="/calendar", tags=["calendar"])
@router.on_event("startup")
async def start_router() -> None:
_logger.debug(f"{router.prefix} router starting.")
@router.get(
"/list",
responses=LM_CALENDARS.lister.responses,
)
async def list_all_calendars(
names: list[str] = Depends(LM_CALENDARS.lister.func),
) -> list[str]:
return names
@router.get(
"/find/{prefix}",
responses=LM_CALENDARS.filter.responses,
)
async def find_calendars(
names: list[str] = Depends(LM_CALENDARS.filter.func),
) -> list[str]:
return names
@router.get(
"/get/{prefix}",
responses=LM_CALENDARS.getter.responses,
)
async def get_calendar(
name: str = Depends(LM_CALENDARS.getter.func),
cfg: Config = Depends(get_config),
) -> list[CalEvent]:
return CalDAV.get_events(name, cfg)
@router.get("/config")
async def get_ui_config(
cfg: Config = Depends(get_config),
) -> CalendarUIConfig:
return cfg.calendar