From 4e1a9fa10d7c1fd1d6d7a3c5bbe363a4e4cedf6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 12 Sep 2023 16:26:12 +0000 Subject: [PATCH] splice DayPartModel from ConfigModel --- api/advent22_api/core/depends.py | 4 +-- api/advent22_api/routers/admin.py | 31 +++++++++++------- ui/src/components/ConfigView.vue | 53 +++++++++++++++++-------------- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/api/advent22_api/core/depends.py b/api/advent22_api/core/depends.py index bd5d093..b97d6dc 100644 --- a/api/advent22_api/core/depends.py +++ b/api/advent22_api/core/depends.py @@ -21,7 +21,7 @@ async def get_days( return sorted(set(door.day for door in cal_cfg.doors)) -async def get_day_parts( +async def get_parts( cfg: Config = Depends(get_config), days: list[int] = Depends(get_days), ) -> dict[int, str]: @@ -48,7 +48,7 @@ async def get_day_parts( async def get_day_part( day: int, - parts: dict[int, str] = Depends(get_day_parts), + parts: dict[int, str] = Depends(get_parts), ) -> str: """ Heute angezeigter Teil der Lösung diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index 9c5ba15..dd90ce6 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -5,7 +5,7 @@ from pydantic import BaseModel from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config from ..core.config import Config, get_config -from ..core.depends import get_day_parts +from ..core.depends import get_parts from ..core.settings import SETTINGS from ._security import require_admin, user_is_admin @@ -21,12 +21,7 @@ async def is_admin( class ConfigModel(BaseModel): class __Puzzle(BaseModel): - class __Part(BaseModel): - day: int - part: str - solution: str - day_parts: list[__Part] begin: date end: date closing: date @@ -61,16 +56,12 @@ async def get_config_model( _: None = Depends(require_admin), cfg: Config = Depends(get_config), cal_cfg: CalendarConfig = Depends(get_calendar_config), - day_parts: dict[int, str] = Depends(get_day_parts), + parts: dict[int, str] = Depends(get_parts), ) -> ConfigModel: return ConfigModel.model_validate( { "puzzle": { "solution": cfg.puzzle.solution, - "day_parts": [ - {"day": day, "part": part} - for day, part in sorted(day_parts.items()) - ], "begin": date.today(), # TODO "end": date.today(), # TODO "closing": date.today(), # TODO @@ -94,8 +85,25 @@ async def get_config_model( ) +class DayPartModel(BaseModel): + day: int + part: str + + +@router.get("/day_parts") +async def get_day_parts( + _: None = Depends(require_admin), + parts: dict[int, str] = Depends(get_parts), +) -> list[DayPartModel]: + return [ + DayPartModel.model_validate({"day": day, "part": part}) + for day, part in sorted(parts.items()) + ] + + @router.get("/doors") async def get_doors( + _: None = Depends(require_admin), cal_cfg: CalendarConfig = Depends(get_calendar_config), ) -> DoorsSaved: """ @@ -108,6 +116,7 @@ async def get_doors( @router.put("/doors") async def put_doors( doors: DoorsSaved, + _: None = Depends(require_admin), cfg: Config = Depends(get_config), cal_cfg: CalendarConfig = Depends(get_calendar_config), ) -> None: diff --git a/ui/src/components/ConfigView.vue b/ui/src/components/ConfigView.vue index 82740c9..31fc56b 100644 --- a/ui/src/components/ConfigView.vue +++ b/ui/src/components/ConfigView.vue @@ -16,13 +16,12 @@
Adventskalender 2023
Lösung
-
{{ admin_config_model.puzzle.solution }}
+
{{ config_model.puzzle.solution }}
Reihenfolge