diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index cda823b..8636e4f 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -19,71 +19,67 @@ async def check_admin( return True -class PrivatePuzzle(BaseModel): - title: str - solution: str - shuffled: str - begin: date - end: date - closing: date - seed: str +class ConfigModel(BaseModel): + class __Puzzle(BaseModel): + solution: str + shuffled: str + begin: date + end: date + closing: date + seed: str + + class __Calendar(BaseModel): + config_file: str + background: str + doors: list[int] + + class __Image(BaseModel): + size: int + border: int + fonts: list[tuple[str, int]] + + class __WebDAV(BaseModel): + url: str + cache_ttl: int + config_file: str + + puzzle: __Puzzle + calendar: __Calendar + image: __Image + webdav: __WebDAV -class PrivateCalendar(BaseModel): - config_file: str - background: str - doors: list[int] - - -class PrivateImage(BaseModel): - size: int - border: int - fonts: list[tuple[str, int]] - - -class PrivateWebDAV(BaseModel): - url: str - cache_ttl: int - config_file: str - - -class PrivateConfig(BaseModel): - puzzle: PrivatePuzzle - calendar: PrivateCalendar - image: PrivateImage - webdav: PrivateWebDAV - - -@router.get("/private_config") -async def get_private_config( +@router.get("/config_model") +async def get_config_model( _: None = Depends(require_admin), cfg: Config = Depends(get_config), cal_cfg: CalendarConfig = Depends(get_calendar_config), shuffled_solution: str = Depends(shuffle_solution), -) -> PrivateConfig: - return PrivateConfig( - puzzle=PrivatePuzzle( - title="Adventskalender 2023", - solution=cfg.puzzle.solution, - shuffled=shuffled_solution, - begin=date.today(), - end=date.today(), - closing=date.today(), - seed=cfg.puzzle.random_seed, - ), - calendar=PrivateCalendar( - config_file=cfg.puzzle.calendar, - background=cal_cfg.background, - doors=[door.day for door in cal_cfg.doors], - ), - image=PrivateImage( - size=500, - border=30, - fonts=[(cfg.server.font, 50)], - ), - webdav=PrivateWebDAV( - url=SETTINGS.webdav.url, - cache_ttl=SETTINGS.webdav.cache_ttl, - config_file=SETTINGS.webdav.config_filename, - ), +) -> ConfigModel: + return ConfigModel.model_validate( + { + "puzzle": { + "solution": cfg.puzzle.solution, + "shuffled": shuffled_solution, + "begin": date.today(), + "end": date.today(), + "closing": date.today(), + "seed": cfg.puzzle.random_seed, + }, + "calendar": { + "config_file": cfg.puzzle.calendar, + "background": cal_cfg.background, + "doors": [door.day for door in cal_cfg.doors], + }, + "image": { + "size": 500, + "border": 30, + "fonts": [(cfg.server.font, 50)], + }, + "webdav": { + "url": SETTINGS.webdav.url, + "cache_ttl": SETTINGS.webdav.cache_ttl, + "config_file": SETTINGS.webdav.config_filename, + }, + } ) diff --git a/ui/src/components/ConfigView.vue b/ui/src/components/ConfigView.vue index e228774..99db282 100644 --- a/ui/src/components/ConfigView.vue +++ b/ui/src/components/ConfigView.vue @@ -10,10 +10,10 @@