add base from lab 1

This commit is contained in:
Матвей
2026-10-08 16:50:41 +03:00
parent 65003b6119
commit de44fc87c7
12 changed files with 887 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field, field_validator
from .storage.memory import Chat, Message
class CreateUserRequest(BaseModel):
model_config = ConfigDict(extra="forbid", strict=True)
username: str = Field(min_length=3, max_length=32, pattern=r"^[a-z0-9_]{3,32}$")
display_name: str = Field(min_length=1, max_length=100)
@field_validator("display_name")
@classmethod
def display_name_must_not_be_whitespace(cls, value: str) -> str:
"""Не допускает обязательное имя, состоящее только из пробелов."""
if not value.strip():
raise ValueError("display_name не может состоять только из пробелов")
return value
class CreateChatRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
title: str = Field(min_length=1, max_length=100)
member_ids: list[UUID] = Field(min_length=1, max_length=100)
@field_validator("title")
@classmethod
def title_must_not_be_whitespace(cls, value: str) -> str:
"""Не допускает обязательное название, состоящее только из пробелов."""
if not value.strip():
raise ValueError("title не может состоять только из пробелов")
return value
class ChatPageResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
items: list[Chat]
next_cursor: str | None
class CreateMessageRequest(BaseModel):
model_config = ConfigDict(extra="forbid", strict=True)
text: str = Field(min_length=1, max_length=4000)
@field_validator("text")
@classmethod
def text_must_not_be_whitespace(cls, value: str) -> str:
"""Не допускает сообщение, состоящее только из пробельных символов."""
if not value.strip():
raise ValueError("text не может состоять только из пробелов")
return value
class MessagePageResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
items: list[Message]
next_cursor: str | None
class ErrorDetails(BaseModel):
model_config = ConfigDict(extra="forbid")
code: str
message: str
request_id: str
class ErrorResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
error: ErrorDetails