From f201b029477b407d089bf01a1829f4a5ecace114 Mon Sep 17 00:00:00 2001 From: Sam Dreyer Date: Mon, 10 Aug 2026 14:03:29 +0000 Subject: [PATCH 1/3] Added a mission type to adventure missions. This will be used in the app to have a few different images depending on the mission type. It is not the prettiest solution but should be fine. --- api_schemas/adventure_mission_schema.py | 2 ++ db_models/adventure_mission_model.py | 2 ++ helpers/constants.py | 1 + services/adventure_mission_service.py | 6 +++++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/api_schemas/adventure_mission_schema.py b/api_schemas/adventure_mission_schema.py index d05d41b2..eab56fde 100644 --- a/api_schemas/adventure_mission_schema.py +++ b/api_schemas/adventure_mission_schema.py @@ -10,6 +10,7 @@ class AdventureMissionCreate(BaseSchema): max_points: int min_points: int nollning_week: int + mission_type: int = 0 class AdventureMissionRead(BaseSchema): @@ -22,4 +23,5 @@ class AdventureMissionRead(BaseSchema): min_points: int nollning_id: int nollning_week: int + mission_type: int created_at: datetime diff --git a/db_models/adventure_mission_model.py b/db_models/adventure_mission_model.py index b2917924..d98d5c6b 100644 --- a/db_models/adventure_mission_model.py +++ b/db_models/adventure_mission_model.py @@ -36,6 +36,8 @@ class AdventureMission_DB(BaseModel_DB): min_points: Mapped[int] = mapped_column() + mission_type: Mapped[int] = mapped_column() + group_missions: Mapped[list["GroupMission_DB"]] = relationship( back_populates="adventure_mission", cascade="all, delete-orphan", init=False ) diff --git a/helpers/constants.py b/helpers/constants.py index f95b334e..c7e7b851 100644 --- a/helpers/constants.py +++ b/helpers/constants.py @@ -53,6 +53,7 @@ # Adventure mission MAX_ADVENTURE_MISSION_NAME = 200 MAX_ADVENTURE_MISSION_DESC = 2000 +NBR_OF_MISSION_TYPES = 5 # Nollning MAX_NOLLNING_NAME = 200 diff --git a/services/adventure_mission_service.py b/services/adventure_mission_service.py index c349f8eb..ad3c89ec 100644 --- a/services/adventure_mission_service.py +++ b/services/adventure_mission_service.py @@ -3,7 +3,7 @@ from api_schemas.adventure_mission_schema import AdventureMissionCreate from db_models.adventure_mission_model import AdventureMission_DB from db_models.nollning_model import Nollning_DB -from helpers.constants import MAX_ADVENTURE_MISSION_DESC, MAX_ADVENTURE_MISSION_NAME +from helpers.constants import MAX_ADVENTURE_MISSION_DESC, MAX_ADVENTURE_MISSION_NAME, NBR_OF_MISSION_TYPES def create_adventure_mission_(db: Session, data: AdventureMissionCreate, nollning_id: int): @@ -28,6 +28,9 @@ 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.mission_type < 0 or data.mission_type > NBR_OF_MISSION_TYPES: + raise HTTPException(400, detail="Mission type must be at least 0 and at most " + str(NBR_OF_MISSION_TYPES)) + new_adventure_mission = AdventureMission_DB( nollning_id=nollning_id, nollning_week=data.nollning_week, @@ -37,6 +40,7 @@ def create_adventure_mission_(db: Session, data: AdventureMissionCreate, nollnin description_en=data.description_en, max_points=data.max_points, min_points=data.min_points, + mission_type=data.mission_type, ) db.add(new_adventure_mission) From 4438d3a3b625922cf8d91781cdb924f3b04e349d Mon Sep 17 00:00:00 2001 From: Sam Dreyer Date: Tue, 11 Aug 2026 13:35:42 +0000 Subject: [PATCH 2/3] Fixed the adventure mission edit function to not accept bad mission attributes. --- services/adventure_mission_service.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/services/adventure_mission_service.py b/services/adventure_mission_service.py index ad3c89ec..5f886c67 100644 --- a/services/adventure_mission_service.py +++ b/services/adventure_mission_service.py @@ -86,6 +86,24 @@ def edit_adventure_mission_(db: Session, id: int, data: AdventureMissionCreate): if not adventure_mission: raise HTTPException(404, detail="Mission not found") + if len(data.title_sv) > MAX_ADVENTURE_MISSION_NAME or len(data.title_en) > MAX_ADVENTURE_MISSION_NAME: + raise HTTPException(400, detail="Title too long") + + if len(data.description_sv) > MAX_ADVENTURE_MISSION_DESC or len(data.description_en) > MAX_ADVENTURE_MISSION_DESC: + raise HTTPException(400, detail="Description too long") + + if data.max_points < data.min_points: + raise HTTPException(400, detail="Max points cannot be lower than min points") + + if data.max_points < 1: + raise HTTPException(400, detail="Max points has to be atleast 1") + + if data.min_points < 0: + raise HTTPException(400, detail="Min points has to be atleast 0") + + if data.mission_type < 0 or data.mission_type > NBR_OF_MISSION_TYPES: + raise HTTPException(400, detail="Mission type must be at least 0 and at most " + str(NBR_OF_MISSION_TYPES)) + for var, value in vars(data).items(): setattr(adventure_mission, var, value) if value is not None else None From 3353a3f54f7674f1eb1240dc257be760b54ea7e1 Mon Sep 17 00:00:00 2001 From: Sam Dreyer Date: Tue, 11 Aug 2026 14:06:24 +0000 Subject: [PATCH 3/3] Edited so that a type is not necessary, can be None. Also figured the max number is probably unnecessary, this would be handled in the app. --- api_schemas/adventure_mission_schema.py | 4 ++-- db_models/adventure_mission_model.py | 4 ++-- helpers/constants.py | 1 - services/adventure_mission_service.py | 10 +++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/api_schemas/adventure_mission_schema.py b/api_schemas/adventure_mission_schema.py index eab56fde..b7f2b007 100644 --- a/api_schemas/adventure_mission_schema.py +++ b/api_schemas/adventure_mission_schema.py @@ -10,7 +10,7 @@ class AdventureMissionCreate(BaseSchema): max_points: int min_points: int nollning_week: int - mission_type: int = 0 + mission_type: int | None = None class AdventureMissionRead(BaseSchema): @@ -23,5 +23,5 @@ class AdventureMissionRead(BaseSchema): min_points: int nollning_id: int nollning_week: int - mission_type: int + mission_type: int | None = None created_at: datetime diff --git a/db_models/adventure_mission_model.py b/db_models/adventure_mission_model.py index d98d5c6b..f9fcf455 100644 --- a/db_models/adventure_mission_model.py +++ b/db_models/adventure_mission_model.py @@ -3,7 +3,7 @@ from sqlalchemy import ForeignKey, String from db_models.base_model import BaseModel_DB -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional from helpers.constants import MAX_ADVENTURE_MISSION_DESC, MAX_ADVENTURE_MISSION_NAME from .base_model import BaseModel_DB @@ -36,7 +36,7 @@ class AdventureMission_DB(BaseModel_DB): min_points: Mapped[int] = mapped_column() - mission_type: Mapped[int] = mapped_column() + mission_type: Mapped[Optional[int]] = mapped_column(default=None) group_missions: Mapped[list["GroupMission_DB"]] = relationship( back_populates="adventure_mission", cascade="all, delete-orphan", init=False diff --git a/helpers/constants.py b/helpers/constants.py index c7e7b851..f95b334e 100644 --- a/helpers/constants.py +++ b/helpers/constants.py @@ -53,7 +53,6 @@ # Adventure mission MAX_ADVENTURE_MISSION_NAME = 200 MAX_ADVENTURE_MISSION_DESC = 2000 -NBR_OF_MISSION_TYPES = 5 # Nollning MAX_NOLLNING_NAME = 200 diff --git a/services/adventure_mission_service.py b/services/adventure_mission_service.py index 5f886c67..07837c8c 100644 --- a/services/adventure_mission_service.py +++ b/services/adventure_mission_service.py @@ -3,7 +3,7 @@ from api_schemas.adventure_mission_schema import AdventureMissionCreate from db_models.adventure_mission_model import AdventureMission_DB from db_models.nollning_model import Nollning_DB -from helpers.constants import MAX_ADVENTURE_MISSION_DESC, MAX_ADVENTURE_MISSION_NAME, NBR_OF_MISSION_TYPES +from helpers.constants import MAX_ADVENTURE_MISSION_DESC, MAX_ADVENTURE_MISSION_NAME def create_adventure_mission_(db: Session, data: AdventureMissionCreate, nollning_id: int): @@ -28,8 +28,8 @@ 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.mission_type < 0 or data.mission_type > NBR_OF_MISSION_TYPES: - raise HTTPException(400, detail="Mission type must be at least 0 and at most " + str(NBR_OF_MISSION_TYPES)) + if data.mission_type is not None and data.mission_type < 0: + raise HTTPException(400, detail="Mission type must be at least 0") new_adventure_mission = AdventureMission_DB( nollning_id=nollning_id, @@ -101,8 +101,8 @@ def edit_adventure_mission_(db: Session, id: int, data: AdventureMissionCreate): if data.min_points < 0: raise HTTPException(400, detail="Min points has to be atleast 0") - if data.mission_type < 0 or data.mission_type > NBR_OF_MISSION_TYPES: - raise HTTPException(400, detail="Mission type must be at least 0 and at most " + str(NBR_OF_MISSION_TYPES)) + if data.mission_type is not None and data.mission_type < 0: + raise HTTPException(400, detail="Mission type must be at least 0") for var, value in vars(data).items(): setattr(adventure_mission, var, value) if value is not None else None