55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""
|
|
Router "cal_aggregate" provides:
|
|
|
|
- listing aggregate calendars
|
|
- finding aggregate calendars by name prefix
|
|
- getting aggregate calendar events by name prefix
|
|
"""
|
|
|
|
from typing import Iterator
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from ovdashboard_api.config import Config
|
|
|
|
from ..dav_calendar import CalEvent, DavCalendar
|
|
from ._common import CalAggregateLister, PrefixFinder, PrefixUnique
|
|
from .calendar import calendar_unique
|
|
|
|
router = APIRouter(prefix="/aggregate", tags=["calendar"])
|
|
|
|
cal_aggregate_lister = CalAggregateLister()
|
|
cal_aggregate_finder = PrefixFinder(cal_aggregate_lister)
|
|
cal_aggregate_unique = PrefixUnique(cal_aggregate_finder)
|
|
|
|
|
|
@router.get("/list", response_model=list[str])
|
|
async def list_aggregate_calendars(
|
|
names: Iterator[str] = Depends(cal_aggregate_lister),
|
|
) -> list[str]:
|
|
return list(names)
|
|
|
|
|
|
@router.get("/find/{prefix}", response_model=list[str])
|
|
async def find_aggregate_calendars(
|
|
names: Iterator[str] = Depends(cal_aggregate_finder),
|
|
) -> list[str]:
|
|
return list(names)
|
|
|
|
|
|
@router.get("/get/{prefix}", response_model=list[CalEvent])
|
|
async def get_aggregate_calendar(
|
|
name: str = Depends(cal_aggregate_unique),
|
|
) -> list[CalEvent]:
|
|
cfg = await Config.get()
|
|
aggregate = cfg.calendar.aggregate[name]
|
|
|
|
calendars = (
|
|
DavCalendar(await calendar_unique(cal_prefix))
|
|
for cal_prefix in aggregate
|
|
)
|
|
|
|
return sorted([
|
|
event
|
|
async for calendar in calendars
|
|
for event in (await calendar.events)
|
|
])
|