50 lines
1.2 KiB
Python
50 lines
1.2 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
|
||
|
|
||
|
router = APIRouter(prefix="/aggregate", tags=["calendar"])
|
||
|
|
||
|
_lister = CalAggregateLister()
|
||
|
_finder = PrefixFinder(_lister)
|
||
|
_unique = PrefixUnique(_finder)
|
||
|
|
||
|
|
||
|
@router.get("/list", response_model=list[str])
|
||
|
async def list_aggregate_calendars(
|
||
|
names: Iterator[str] = Depends(_lister),
|
||
|
) -> list[str]:
|
||
|
return list(names)
|
||
|
|
||
|
|
||
|
@router.get("/find/{prefix}", response_model=list[str])
|
||
|
async def find_aggregate_calendars(
|
||
|
names: Iterator[str] = Depends(_finder),
|
||
|
) -> list[str]:
|
||
|
return list(names)
|
||
|
|
||
|
|
||
|
@router.get("/get/{prefix}", response_model=list[CalEvent])
|
||
|
async def get_aggregate_calendar(
|
||
|
name: Iterator[str] = Depends(_unique),
|
||
|
) -> list[CalEvent]:
|
||
|
cfg = await Config.get()
|
||
|
aggregate = cfg.calendar.aggregate[name]
|
||
|
|
||
|
return sorted([
|
||
|
event
|
||
|
for calendar_name in aggregate
|
||
|
for event in (await DavCalendar(calendar_name).events)
|
||
|
])
|