From 5fe5d92ce4a367dc48e2050ce9a8554faeaa2883 Mon Sep 17 00:00:00 2001 From: georgelgeback Date: Tue, 21 Jul 2026 17:14:50 +0000 Subject: [PATCH 1/2] Add unlock codes and unlock hints --- api_schemas/adventure_mission_schema.py | 6 ++++++ db_models/adventure_mission_model.py | 23 ++++++++++++++++++----- helpers/constants.py | 2 ++ services/adventure_mission_service.py | 3 +++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/api_schemas/adventure_mission_schema.py b/api_schemas/adventure_mission_schema.py index d05d41b..b4fb62f 100644 --- a/api_schemas/adventure_mission_schema.py +++ b/api_schemas/adventure_mission_schema.py @@ -10,6 +10,9 @@ class AdventureMissionCreate(BaseSchema): max_points: int min_points: int nollning_week: int + unlock_code: str | None = None + unlock_hint_sv: str | None = None + unlock_hint_en: str | None = None class AdventureMissionRead(BaseSchema): @@ -22,4 +25,7 @@ class AdventureMissionRead(BaseSchema): min_points: int nollning_id: int nollning_week: int + unlock_code: str | None = None + unlock_hint_sv: str | None = None + unlock_hint_en: str | None = None created_at: datetime diff --git a/db_models/adventure_mission_model.py b/db_models/adventure_mission_model.py index b291792..0588d8a 100644 --- a/db_models/adventure_mission_model.py +++ b/db_models/adventure_mission_model.py @@ -3,9 +3,14 @@ from sqlalchemy import ForeignKey, String from db_models.base_model import BaseModel_DB -from typing import TYPE_CHECKING - -from helpers.constants import MAX_ADVENTURE_MISSION_DESC, MAX_ADVENTURE_MISSION_NAME +from typing import TYPE_CHECKING, Optional + +from helpers.constants import ( + MAX_ADVENTURE_MISSION_DESC, + MAX_ADVENTURE_MISSION_NAME, + MAX_ADVENTURE_MISSION_UNLOCK_CODE, + MAX_ADVENTURE_MISSION_UNLOCK_HINT, +) from .base_model import BaseModel_DB from sqlalchemy.orm import relationship, Mapped, mapped_column from .group_mission_model import GroupMission_DB @@ -36,8 +41,16 @@ class AdventureMission_DB(BaseModel_DB): min_points: Mapped[int] = mapped_column() - group_missions: Mapped[list["GroupMission_DB"]] = relationship( - back_populates="adventure_mission", cascade="all, delete-orphan", init=False + group_missions: Mapped[list["GroupMission_DB"]] = ( + relationship( # many-many relationship with groups requires this, so that groups can track which missions they have completed. + back_populates="adventure_mission", cascade="all, delete-orphan", init=False + ) ) + # Not secret, passed along with all fetches which can be made by basically anyone. + unlock_code: Mapped[Optional[str]] = mapped_column(String(MAX_ADVENTURE_MISSION_UNLOCK_CODE), default=None) + + unlock_hint_sv: Mapped[Optional[str]] = mapped_column(String(MAX_ADVENTURE_MISSION_UNLOCK_HINT), default=None) + unlock_hint_en: Mapped[Optional[str]] = mapped_column(String(MAX_ADVENTURE_MISSION_UNLOCK_HINT), default=None) + created_at: Mapped[datetime_utc] = created_at_column() diff --git a/helpers/constants.py b/helpers/constants.py index f95b334..4eb722b 100644 --- a/helpers/constants.py +++ b/helpers/constants.py @@ -53,6 +53,8 @@ # Adventure mission MAX_ADVENTURE_MISSION_NAME = 200 MAX_ADVENTURE_MISSION_DESC = 2000 +MAX_ADVENTURE_MISSION_UNLOCK_CODE = 200 +MAX_ADVENTURE_MISSION_UNLOCK_HINT = 200 # Nollning MAX_NOLLNING_NAME = 200 diff --git a/services/adventure_mission_service.py b/services/adventure_mission_service.py index c349f8e..71700ef 100644 --- a/services/adventure_mission_service.py +++ b/services/adventure_mission_service.py @@ -37,6 +37,9 @@ def create_adventure_mission_(db: Session, data: AdventureMissionCreate, nollnin description_en=data.description_en, max_points=data.max_points, min_points=data.min_points, + unlock_code=data.unlock_code, + unlock_hint_sv=data.unlock_hint_sv, + unlock_hint_en=data.unlock_hint_en, ) db.add(new_adventure_mission) From 2381079e86ac16a06f468f41606d3e157cfb977c Mon Sep 17 00:00:00 2001 From: georgelgeback Date: Wed, 22 Jul 2026 08:02:01 +0000 Subject: [PATCH 2/2] Allow for clearing of unlock code and hints, and remove any input of empty strings we get --- services/adventure_mission_service.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/services/adventure_mission_service.py b/services/adventure_mission_service.py index 71700ef..d3337e1 100644 --- a/services/adventure_mission_service.py +++ b/services/adventure_mission_service.py @@ -28,6 +28,13 @@ def create_adventure_mission_(db: Session, data: AdventureMissionCreate, nollnin if data.min_points < 0: raise HTTPException(400, detail="Min points has to be atleast 0") + if data.unlock_code == "": # Easy guard against accidentally setting unlock_code to empty string + data.unlock_code = None + if data.unlock_hint_sv == "": + data.unlock_hint_sv = None + if data.unlock_hint_en == "": + data.unlock_hint_en = None + new_adventure_mission = AdventureMission_DB( nollning_id=nollning_id, nollning_week=data.nollning_week, @@ -85,8 +92,16 @@ def edit_adventure_mission_(db: Session, id: int, data: AdventureMissionCreate): if not adventure_mission: raise HTTPException(404, detail="Mission not found") + if data.unlock_code == "": # Easy guard against accidentally setting unlock_code to empty string + data.unlock_code = None + if data.unlock_hint_sv == "": + data.unlock_hint_sv = None + if data.unlock_hint_en == "": + data.unlock_hint_en = None + for var, value in vars(data).items(): - setattr(adventure_mission, var, value) if value is not None else None + # Allow for clearing of code by allowing setting attributes to None + setattr(adventure_mission, var, value) db.commit() db.refresh(adventure_mission)