Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api_schemas/adventure_mission_schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from api_schemas.base_schema import BaseSchema
from helpers.types import MISSION_CATEGORIES


class AdventureMissionCreate(BaseSchema):
Expand All @@ -10,6 +11,7 @@ class AdventureMissionCreate(BaseSchema):
max_points: int
min_points: int
nollning_week: int
mission_category: MISSION_CATEGORIES | None = None
unlock_code: str | None = None
unlock_hint_sv: str | None = None
unlock_hint_en: str | None = None
Expand All @@ -25,6 +27,7 @@ class AdventureMissionRead(BaseSchema):
min_points: int
nollning_id: int
nollning_week: int
mission_category: str
unlock_code: str | None = None
unlock_hint_sv: str | None = None
unlock_hint_en: str | None = None
Expand Down
3 changes: 3 additions & 0 deletions db_models/adventure_mission_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .base_model import BaseModel_DB
from sqlalchemy.orm import relationship, Mapped, mapped_column
from .group_mission_model import GroupMission_DB
from helpers.types import MISSION_CATEGORIES

if TYPE_CHECKING:
from .nollning_model import Nollning_DB
Expand Down Expand Up @@ -41,6 +42,8 @@ class AdventureMission_DB(BaseModel_DB):

min_points: Mapped[int] = mapped_column()

mission_category: Mapped[Optional[MISSION_CATEGORIES]] = mapped_column(default="Spel")

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
Expand Down
2 changes: 2 additions & 0 deletions helpers/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def force_utc(date: datetime):

MISSION_CONFIRMED_TYPES = Literal["Accepted", "Failed", "Review"]

MISSION_CATEGORIES = Literal["Barbiedans", "Fadder", "Kreativ", "Resa", "Spel", "Tävling", "Älg"]

ASSETS_BASE_PATH = os.getenv("ASSETS_BASE_PATH")


Expand Down
13 changes: 13 additions & 0 deletions services/adventure_mission_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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_category=data.mission_category if data.mission_category is not None else "Spel",
unlock_code=data.unlock_code,
unlock_hint_sv=data.unlock_hint_sv,
unlock_hint_en=data.unlock_hint_en,
Expand Down Expand Up @@ -121,13 +122,25 @@ def edit_adventure_mission_(db: Session, id: int, data: AdventureMissionCreate):
if not adventure_mission:
raise HTTPException(404, detail="Mission not found")

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.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

if data.mission_category is None:
data.mission_category = "Spel"

for var, value in vars(data).items():
# Allow for clearing of unlock_code by allowing setting attributes to None
setattr(adventure_mission, var, value)
Expand Down
Loading