forked from mtusi2026/mtusi2026lab2
34 lines
806 B
Python
34 lines
806 B
Python
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
|