feat: update pydantic schemas for lab5 variants
This commit is contained in:
+3
-7
@@ -10,8 +10,7 @@ class CreateUser(BaseModel):
|
|||||||
@field_validator("display_name", "password")
|
@field_validator("display_name", "password")
|
||||||
@classmethod
|
@classmethod
|
||||||
def _not_blank(cls, v: str) -> str:
|
def _not_blank(cls, v: str) -> str:
|
||||||
if not v.strip():
|
if not v.strip(): raise ValueError("must not be blank")
|
||||||
raise ValueError("must not be blank")
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
class CreateChat(BaseModel):
|
class CreateChat(BaseModel):
|
||||||
@@ -22,20 +21,17 @@ class CreateChat(BaseModel):
|
|||||||
@field_validator("title")
|
@field_validator("title")
|
||||||
@classmethod
|
@classmethod
|
||||||
def _title_not_blank(cls, v: str) -> str:
|
def _title_not_blank(cls, v: str) -> str:
|
||||||
if not v.strip():
|
if not v.strip(): raise ValueError("title must not be blank")
|
||||||
raise ValueError("title must not be blank")
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@field_validator("member_ids")
|
@field_validator("member_ids")
|
||||||
@classmethod
|
@classmethod
|
||||||
def _unique_members(cls, v: list[UUID]) -> list[UUID]:
|
def _unique_members(cls, v: list[UUID]) -> list[UUID]:
|
||||||
if len(set(v)) != len(v):
|
if len(set(v)) != len(v): raise ValueError("duplicate member_ids")
|
||||||
raise ValueError("duplicate member_ids")
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
class CreateMessage(BaseModel):
|
class CreateMessage(BaseModel):
|
||||||
model_config = ConfigDict(extra="forbid")
|
model_config = ConfigDict(extra="forbid")
|
||||||
# min_length=0 разрешает пустой текст, если прикреплен файл
|
|
||||||
text: str = Field(min_length=0, max_length=4000)
|
text: str = Field(min_length=0, max_length=4000)
|
||||||
attachment_ids: list[UUID] | None = None
|
attachment_ids: list[UUID] | None = None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user