Opening any shared deck answered 500 — ResponseValidationError, "Input should be a valid integer" for user_id. The ownership migration made those columns nullable and the response models still declared `user_id: int`, so the first read of a deck after it was a crash rather than a page. A learner hit it on Cards. FlashcardDeckResponse, DocumentResponse and QuizResponse now allow None, with a test that walks the three and fails if any of them promises an owner again. The grant-input schemas were left alone on purpose: their user_id names the person a grant is for, and a grant with nobody in it is not a thing. Also gone: send_login_code_email, forty-eight lines of email template for a feature that no longer exists. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TqXevQJhxFrM7jJg82cgZN
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, field_validator
|
|
|
|
|
|
class SectionCreate(BaseModel):
|
|
name: str
|
|
start_page: int
|
|
end_page: int
|
|
|
|
@field_validator("end_page")
|
|
@classmethod
|
|
def end_after_start(cls, v, info):
|
|
if "start_page" in info.data and v <= info.data["start_page"]:
|
|
raise ValueError("end_page must be greater than start_page")
|
|
return v
|
|
|
|
@field_validator("start_page")
|
|
@classmethod
|
|
def start_positive(cls, v):
|
|
if v < 1:
|
|
raise ValueError("start_page must be at least 1")
|
|
return v
|
|
|
|
|
|
class SectionResponse(BaseModel):
|
|
id: int
|
|
document_id: int
|
|
name: str
|
|
start_page: int
|
|
end_page: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class DocumentResponse(BaseModel):
|
|
id: int
|
|
# Nullable: bank content has no owner, and a schema that promises an
|
|
# int where the column says NULL is a 500 on serialisation.
|
|
user_id: int | None = None
|
|
original_filename: str
|
|
total_pages: int | None
|
|
status: str
|
|
error_message: str | None
|
|
uploaded_at: datetime
|
|
sections: list[SectionResponse] = []
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class DocumentStatusResponse(BaseModel):
|
|
id: int
|
|
status: str
|
|
total_pages: int | None
|
|
error_message: str | None
|