67 lines
1.5 KiB
Python
67 lines
1.5 KiB
Python
from pydantic import BaseModel, Field
|
|
from uuid import UUID
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
# --- Ошибки ---
|
|
class ErrorDetail(BaseModel):
|
|
code: str
|
|
message: str
|
|
request_id: str
|
|
|
|
class Error(BaseModel):
|
|
error: ErrorDetail
|
|
|
|
|
|
# --- Пользователь ---
|
|
class CreateUser(BaseModel):
|
|
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)
|
|
|
|
class User(BaseModel):
|
|
id: UUID
|
|
username: str
|
|
display_name: str
|
|
created_at: datetime
|
|
|
|
|
|
# --- Сессии ---
|
|
class Session(BaseModel):
|
|
token: str
|
|
token_type: str = "Bearer"
|
|
expires_at: datetime
|
|
user: User
|
|
|
|
|
|
# --- Чаты ---
|
|
class CreateChat(BaseModel):
|
|
title: str = Field(..., min_length=1, max_length=100)
|
|
member_ids: List[UUID] = Field(..., min_length=1, max_length=100)
|
|
|
|
class Chat(BaseModel):
|
|
id: UUID
|
|
title: str
|
|
member_ids: List[UUID]
|
|
created_at: datetime
|
|
|
|
class ChatPage(BaseModel):
|
|
items: List[Chat]
|
|
next_cursor: Optional[str] = None
|
|
|
|
|
|
# --- Сообщения ---
|
|
class CreateMessage(BaseModel):
|
|
text: str = Field(..., min_length=1, max_length=4000)
|
|
|
|
class Message(BaseModel):
|
|
id: UUID
|
|
chat_id: UUID
|
|
sender_id: UUID
|
|
text: str
|
|
created_at: datetime
|
|
attachment_ids: List[UUID] = [] # <--- Обязательно для контракта!
|
|
|
|
class MessagePage(BaseModel):
|
|
items: List[Message]
|
|
next_cursor: Optional[str] = None |