Skip to content
Open
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
12 changes: 10 additions & 2 deletions backend/app/schemas/interview.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class DsaTopicCreate(BaseModel):
difficulty: str


class CustomInterviewCreate(BaseModel):
# Shared fields (NO validation here)
class CustomInterviewBase(BaseModel):
description: str
position: str
experience: str
Expand All @@ -31,15 +32,20 @@ class CustomInterviewCreate(BaseModel):
questions: list[CustomQuestionCreate] = []
dsa_topics: list[DsaTopicCreate] = []


# Validation should only happen during creation
class CustomInterviewCreate(CustomInterviewBase):
@model_validator(mode="after")
def validate_times_and_scores(self) -> "CustomInterviewCreate":
tz = self.start_time.tzinfo
now = datetime.now(tz)

if self.start_time <= now:
raise BadRequestError("start_time must be in the future")

if self.end_time <= now:
raise BadRequestError("end_time must be in the future")

if self.submission_deadline <= now:
raise BadRequestError("submission_deadline must be in the future")

Expand All @@ -49,6 +55,7 @@ def validate_times_and_scores(self) -> "CustomInterviewCreate":
if self.dsa_score is not None or self.dev_score is not None:
dsa = self.dsa_score or 0
dev = self.dev_score or 0

if dsa + dev != 100:
raise BadRequestError("The sum of dsa_score and dev_score must be exactly 100")

Expand All @@ -71,7 +78,8 @@ class Config:
from_attributes = True


class CustomInterviewResponse(CustomInterviewCreate):
# Response should not trigger create validation
class CustomInterviewResponse(CustomInterviewBase):
id: int
org_id: int
questions: list[CustomQuestionResponse] = [] # type: ignore[assignment]
Expand Down
Loading