forked from mtusi2026/mtusi2026lab5
chore: copy lab4 solution (api, nginx, migrations, tests, s3)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
|
||||
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)
|
||||
|
||||
@field_validator("display_name", "password")
|
||||
@classmethod
|
||||
def _not_blank(cls, v: str) -> str:
|
||||
if not v.strip():
|
||||
raise ValueError("must not be blank")
|
||||
return v
|
||||
|
||||
class CreateChat(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_not_blank(cls, v: str) -> str:
|
||||
if not v.strip():
|
||||
raise ValueError("title must not be blank")
|
||||
return v
|
||||
|
||||
@field_validator("member_ids")
|
||||
@classmethod
|
||||
def _unique_members(cls, v: list[UUID]) -> list[UUID]:
|
||||
if len(set(v)) != len(v):
|
||||
raise ValueError("duplicate member_ids")
|
||||
return v
|
||||
|
||||
class CreateMessage(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
# min_length=0 разрешает пустой текст, если прикреплен файл
|
||||
text: str = Field(min_length=0, max_length=4000)
|
||||
attachment_ids: list[UUID] | None = None
|
||||
|
||||
class SessionResponse(BaseModel):
|
||||
token: str
|
||||
token_type: str = "Bearer"
|
||||
expires_at: str
|
||||
user: dict
|
||||
|
||||
class AttachmentResponse(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
id: UUID
|
||||
chat_id: UUID
|
||||
owner_id: UUID
|
||||
filename: str
|
||||
content_type: str
|
||||
size_bytes: int
|
||||
sha256: str
|
||||
status: str
|
||||
error_code: str | None = None
|
||||
variants: list = []
|
||||
created_at: str
|
||||
updated_at: str
|
||||
Reference in New Issue
Block a user