forked from mtusi2026/mtusi2026lab3
Исправление ошибок ЛР3
This commit is contained in:
+19
-1
@@ -1,7 +1,13 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, ConfigDict, field_validator
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
def _not_blank(value: str) -> str:
|
||||
if not value.strip():
|
||||
raise ValueError("must contain non-whitespace characters")
|
||||
return value
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
id: str
|
||||
username: str
|
||||
@@ -10,10 +16,14 @@ class User(BaseModel):
|
||||
|
||||
|
||||
class CreateUser(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
username: str = Field(..., pattern=r"^[a-z0-9_]{3,32}$")
|
||||
display_name: str = Field(..., min_length=1, max_length=100)
|
||||
password: str = Field(..., min_length=12, max_length=128)
|
||||
|
||||
_check_display_name = field_validator("display_name")(_not_blank)
|
||||
|
||||
|
||||
class Chat(BaseModel):
|
||||
id: str
|
||||
@@ -23,9 +33,13 @@ class Chat(BaseModel):
|
||||
|
||||
|
||||
class CreateChat(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
title: str = Field(..., min_length=1, max_length=100)
|
||||
member_ids: List[str] = Field(..., min_length=1, max_length=100)
|
||||
|
||||
_check_title = field_validator("title")(_not_blank)
|
||||
|
||||
|
||||
class Message(BaseModel):
|
||||
id: str
|
||||
@@ -36,8 +50,12 @@ class Message(BaseModel):
|
||||
|
||||
|
||||
class CreateMessage(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
text: str = Field(..., min_length=1, max_length=4000)
|
||||
|
||||
_check_text = field_validator("text")(_not_blank)
|
||||
|
||||
|
||||
class ChatPage(BaseModel):
|
||||
items: List[Chat]
|
||||
|
||||
Reference in New Issue
Block a user