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 15:46:12 +00:00
from ...core.caldav import CalDAV, CalEvent
from ...core.config import CalendarUIConfig, Config, get_config
from ._common import LM_CALENDARS
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",
responses=LM_CALENDARS.lister.responses,
)
async def list_all_calendars(
names: list[str] = Depends(LM_CALENDARS.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}",
responses=LM_CALENDARS.filter.responses,
)
2022-09-03 02:00:07 +00:00
async def find_calendars(
2023-10-26 15:46:12 +00:00
names: list[str] = Depends(LM_CALENDARS.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}",
responses=LM_CALENDARS.getter.responses,
)
2022-09-03 02:00:07 +00:00
async def get_calendar(
2023-10-26 15:46:12 +00:00
name: str = Depends(LM_CALENDARS.getter.func),
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