From c93ec069257c10be189f0369593055a2b9b8cfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 14 Sep 2023 23:40:06 +0000 Subject: [PATCH] use EventDays in GET admin/config_model --- api/advent22_api/core/depends.py | 19 ++++++++++++++++++- api/advent22_api/routers/admin.py | 15 +++++++++------ ui/src/components/admin/ConfigView.vue | 14 +++++++------- ui/src/lib/api.ts | 4 ++-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/api/advent22_api/core/depends.py b/api/advent22_api/core/depends.py index 29bfbc5..b8482a6 100644 --- a/api/advent22_api/core/depends.py +++ b/api/advent22_api/core/depends.py @@ -1,3 +1,4 @@ +from datetime import date from io import BytesIO from typing import cast @@ -7,7 +8,7 @@ from PIL import Image, ImageFont from .advent_image import _XY, AdventImage from .calendar_config import CalendarConfig, get_calendar_config from .config import Config, get_config -from .helpers import Random, list_images_auto, load_image, set_len +from .helpers import EventDays, Random, list_images_auto, load_image, set_len from .webdav import WebDAV @@ -21,6 +22,22 @@ async def get_all_days( return sorted(set(door.day for door in cal_cfg.doors)) +async def get_all_event_days( + days: list[int] = Depends(get_all_days), +) -> EventDays: + """ + Aktuelles EventDays Objekt + """ + + return EventDays.get( + today=date.today(), + begin_month=12, + begin_day=1, + events_after=[day - 1 for day in days], + closing_after=90, + ) + + async def get_all_parts( cfg: Config = Depends(get_config), days: list[int] = Depends(get_all_days), diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index 5601c91..e3eeb79 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -3,9 +3,11 @@ from datetime import date from fastapi import APIRouter, Depends from pydantic import BaseModel +from advent22_api.core.helpers import EventDays + from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config from ..core.config import Config, get_config -from ..core.depends import get_all_image_names, get_all_parts +from ..core.depends import get_all_event_days, get_all_image_names, get_all_parts from ..core.settings import SETTINGS from ._security import require_admin, user_is_admin @@ -22,9 +24,9 @@ async def is_admin( class ConfigModel(BaseModel): class __Puzzle(BaseModel): solution: str - begin: date + first: date + last: date end: date - closing: date seed: str class __Calendar(BaseModel): @@ -56,6 +58,7 @@ async def get_config_model( _: None = Depends(require_admin), cfg: Config = Depends(get_config), cal_cfg: CalendarConfig = Depends(get_calendar_config), + event_days: EventDays = Depends(get_all_event_days), ) -> ConfigModel: """ Kombiniert aus privaten `settings`, `config` und `calendar_config` @@ -65,9 +68,9 @@ async def get_config_model( { "puzzle": { "solution": cfg.puzzle.solution, - "begin": date.today(), # TODO - "end": date.today(), # TODO - "closing": date.today(), # TODO + "first": event_days.first, + "last": event_days.last, + "end": event_days.end, "seed": cfg.puzzle.random_seed, }, "calendar": { diff --git a/ui/src/components/admin/ConfigView.vue b/ui/src/components/admin/ConfigView.vue index 9b2b5fa..591932e 100644 --- a/ui/src/components/admin/ConfigView.vue +++ b/ui/src/components/admin/ConfigView.vue @@ -21,13 +21,13 @@
dd-hh-mm-ss
Erstes Türchen
-
{{ config_model.puzzle.begin }}
+
{{ config_model.puzzle.first }}
Letztes Türchen
-
{{ config_model.puzzle.end }}
+
{{ config_model.puzzle.last }}
-
Rätsel schließt
-
{{ config_model.puzzle.closing }}
+
Rätsel schließt nach
+
{{ config_model.puzzle.end }}
Zufalls-Seed
@@ -142,9 +142,9 @@ export default class extends Vue { public config_model: ConfigModel = { puzzle: { solution: "ABCDEFGHIJKLMNOPQRSTUVWX", - begin: "01.12.2023", - end: "24.12.2023", - closing: "01.04.2024", + first: "01.12.2023", + last: "24.12.2023", + end: "01.04.2024", seed: "", }, calendar: { diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts index 2ce8b46..d0feb70 100644 --- a/ui/src/lib/api.ts +++ b/ui/src/lib/api.ts @@ -1,9 +1,9 @@ export interface ConfigModel { puzzle: { solution: string; - begin: string; + first: string; + last: string; end: string; - closing: string; seed: string; }; calendar: {