From c92398118b9b973a295bffdabd4ff9fa7a595eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 26 Oct 2023 17:48:33 +0200 Subject: [PATCH] minor refac --- api/ovdashboard_api/routers/v1/_common.py | 10 +++++----- api/ovdashboard_api/routers/v1/calendar.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/api/ovdashboard_api/routers/v1/_common.py b/api/ovdashboard_api/routers/v1/_common.py index 79046d5..3ac55b6 100644 --- a/api/ovdashboard_api/routers/v1/_common.py +++ b/api/ovdashboard_api/routers/v1/_common.py @@ -25,12 +25,12 @@ _RESPONSE_OK = { Params = ParamSpec("Params") Return = TypeVar("Return") -type _Dependable[**Params, Return] = Callable[Params, Awaitable[Return]] +type DependableFn[**Params, Return] = Callable[Params, Awaitable[Return]] @dataclass(slots=True, frozen=True) class Dependable(Generic[Params, Return]): - func: _Dependable[Params, Return] + func: DependableFn[Params, Return] responses: dict = field(default_factory=lambda: _RESPONSE_OK.copy()) @@ -92,13 +92,13 @@ class ListManager: ) @classmethod - def from_lister_fn(cls, lister_fn: _Dependable[[], list[str]]) -> Self: + def from_lister_fn(cls, lister_fn: DependableFn[[], list[str]]) -> Self: return cls.from_lister(Dependable(lister_fn)) def get_remote_path( path_name: str, -) -> _Dependable[[], str]: +) -> DependableFn[[], str]: async def _get_remote_path() -> str: cfg = await get_config() return getattr(cfg, path_name) @@ -112,7 +112,7 @@ RP_TEXT = get_remote_path("text_dir") def get_file_lister( - rp: _Dependable[[], str], + rp: DependableFn[[], str], *, re: re.Pattern[str], ) -> Dependable[[], list[str]]: diff --git a/api/ovdashboard_api/routers/v1/calendar.py b/api/ovdashboard_api/routers/v1/calendar.py index 4d1dc92..e5a34bd 100644 --- a/api/ovdashboard_api/routers/v1/calendar.py +++ b/api/ovdashboard_api/routers/v1/calendar.py @@ -34,14 +34,20 @@ async def list_all_calendars( return names -@router.get("/find/{prefix}") +@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}") +@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),