diff --git a/api/advent22_api/calendar_config.py b/api/advent22_api/calendar_config.py index e496012..b1fec3b 100644 --- a/api/advent22_api/calendar_config.py +++ b/api/advent22_api/calendar_config.py @@ -4,9 +4,8 @@ from typing import TypeAlias import tomli_w from pydantic import BaseModel -from .config import get_config +from .config import Config, get_config from .dav_common import dav_get_textfile_content, dav_write_textfile_content -from .settings import SETTINGS class DoorSaved(BaseModel): @@ -41,9 +40,9 @@ async def get_calendar_config() -> CalendarConfig: return CalendarConfig.model_validate(tomllib.loads(txt)) -async def set_calendar_config(cal_cfg: CalendarConfig) -> None: +async def set_calendar_config(cfg: Config, cal_cfg: CalendarConfig) -> None: await dav_write_textfile_content( - path=SETTINGS.config_filename, + path=f"files/{cfg.puzzle.calendar}", content=tomli_w.dumps( cal_cfg.model_dump( exclude_defaults=True, diff --git a/api/advent22_api/routers/general.py b/api/advent22_api/routers/general.py index ff4eb0b..789a0b1 100644 --- a/api/advent22_api/routers/general.py +++ b/api/advent22_api/routers/general.py @@ -8,6 +8,7 @@ from ..calendar_config import ( get_calendar_config, set_calendar_config, ) +from ..config import Config, get_config from ..dav_common import dav_get_file from ._misc import api_return_image @@ -44,6 +45,7 @@ async def get_doors( @router.put("/doors") async def put_doors( doors: DoorsSaved, + cfg: Config = Depends(get_config), cal_cfg: CalendarConfig = Depends(get_calendar_config), ) -> None: """ @@ -54,4 +56,4 @@ async def put_doors( doors, key=lambda door: door.day, ) - await set_calendar_config(cal_cfg) + await set_calendar_config(cfg, cal_cfg)