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

63 lines
1.3 KiB
Python
Raw Normal View History

2022-09-05 12:54:02 +00:00
"""
Router "calendar" provides:
- listing calendars
- finding calendars by name prefix
- getting calendar events by calendar name prefix
"""
2023-10-26 16:21:07 +00:00
import logging
2022-09-03 02:00:07 +00:00
2022-09-04 14:14:22 +00:00
from fastapi import APIRouter, Depends
2022-09-02 19:21:15 +00:00
2023-10-26 16:26:51 +00:00
from ...core.config import CalendarUIConfig, Config
2023-11-09 11:13:48 +00:00
from ...core.dav.caldav import CalDAV, CalEvent
2023-10-26 17:17:16 +00:00
from ._common import LM_CALENDAR, get_config
2022-09-02 19:21:15 +00:00
2023-10-26 16:21:07 +00:00
_logger = logging.getLogger(__name__)
2022-09-08 14:07:33 +00:00
2022-09-02 19:21:15 +00:00
router = APIRouter(prefix="/calendar", tags=["calendar"])
2022-09-03 02:00:07 +00:00
2022-09-08 14:07:33 +00:00
@router.on_event("startup")
async def start_router() -> None:
_logger.debug(f"{router.prefix} router starting.")
2023-10-26 15:46:12 +00:00
@router.get(
"/list",
2023-10-26 17:17:16 +00:00
responses=LM_CALENDAR.lister.responses,
2023-10-26 15:46:12 +00:00
)
2023-10-26 21:17:38 +00:00
async def list_calendars(
2023-10-26 17:17:16 +00:00
names: list[str] = Depends(LM_CALENDAR.lister.func),
2022-09-03 02:00:07 +00:00
) -> list[str]:
2023-10-26 15:46:12 +00:00
return names
2022-09-03 02:00:07 +00:00
2023-10-26 15:48:33 +00:00
@router.get(
"/find/{prefix}",
2023-10-26 17:17:16 +00:00
responses=LM_CALENDAR.filter.responses,
2023-10-26 15:48:33 +00:00
)
2022-09-03 02:00:07 +00:00
async def find_calendars(
2023-10-26 17:17:16 +00:00
names: list[str] = Depends(LM_CALENDAR.filter.func),
2022-09-03 02:00:07 +00:00
) -> list[str]:
2023-10-26 15:46:12 +00:00
return names
2022-09-03 02:00:07 +00:00
2023-10-26 15:48:33 +00:00
@router.get(
"/get/{prefix}",
2023-10-26 17:17:16 +00:00
responses=LM_CALENDAR.getter.responses,
2023-10-26 15:48:33 +00:00
)
2022-09-03 02:00:07 +00:00
async def get_calendar(
2023-10-26 17:17:16 +00:00
name: str = Depends(LM_CALENDAR.getter.func),
2023-10-26 15:46:12 +00:00
cfg: Config = Depends(get_config),
2022-09-04 14:14:22 +00:00
) -> list[CalEvent]:
2023-10-26 16:04:03 +00:00
return await CalDAV.get_events(name, cfg)
2022-09-15 22:32:11 +00:00
2023-10-26 15:46:12 +00:00
@router.get("/config")
2022-09-15 22:32:11 +00:00
async def get_ui_config(
2023-10-26 15:46:12 +00:00
cfg: Config = Depends(get_config),
2022-09-15 22:32:11 +00:00
) -> CalendarUIConfig:
return cfg.calendar