Skip to content
Open
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
2 changes: 2 additions & 0 deletions api_schemas/adventure_mission_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AdventureMissionCreate(BaseSchema):
max_points: int
min_points: int
nollning_week: int
mission_type: int | None = None


class AdventureMissionRead(BaseSchema):
Expand All @@ -22,4 +23,5 @@ class AdventureMissionRead(BaseSchema):
min_points: int
nollning_id: int
nollning_week: int
mission_type: int | None = None
created_at: datetime
4 changes: 3 additions & 1 deletion db_models/adventure_mission_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,6 +36,8 @@ class AdventureMission_DB(BaseModel_DB):

min_points: 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
)
Expand Down
22 changes: 22 additions & 0 deletions services/adventure_mission_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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,
nollning_week=data.nollning_week,
Expand All @@ -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)
Expand Down Expand Up @@ -82,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 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

Expand Down
Loading