ЛР2: PostgreSQL, сессии (Basic + Bearer), Compose, миграции
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
|
||||
|
||||
from utils.dates import UtcDatetime
|
||||
|
||||
|
||||
class CreateMessageRequest(BaseModel):
|
||||
# extra="forbid": клиент не может прислать sender_id.
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
text: StrictStr = Field(min_length=1, max_length=4000)
|
||||
|
||||
@field_validator("text")
|
||||
def validate_text(cls, v):
|
||||
if not v.strip():
|
||||
raise ValueError("text must not be blank")
|
||||
return v
|
||||
|
||||
|
||||
class MessageResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
chat_id: UUID
|
||||
sender_id: UUID
|
||||
text: str
|
||||
created_at: UtcDatetime
|
||||
|
||||
|
||||
class MessagePageResponse(BaseModel):
|
||||
items: list[MessageResponse]
|
||||
next_cursor: str | None
|
||||
Reference in New Issue
Block a user