добавлена постгря и начальная схема

This commit is contained in:
2026-10-07 21:44:56 +03:00
parent 65003b6119
commit 789bea2f1e
14 changed files with 904 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
from datetime import datetime
from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field, field_validator
class CreateUser(BaseModel):
model_config = ConfigDict(extra="forbid")
username: str = Field(
min_length=3,
max_length=32,
pattern=r"^[a-z0-9_]+$",
)
display_name: str = Field(
min_length=1,
max_length=100,
)
@field_validator("display_name")
@classmethod
def validate_display_name(cls, value: str) -> str:
if not value.strip():
raise ValueError("Display name must not be blank")
return value
class User(BaseModel):
id: UUID
username: str
display_name: str
created_at: datetime
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 validate_title(cls, value: str) -> str:
if not value.strip():
raise ValueError("Chat title must not be blank")
return value
@field_validator("member_ids")
@classmethod
def validate_member_ids(cls, value: list[UUID]) -> list[UUID]:
if len(value) != len(set(value)):
raise ValueError("Member IDs must be unique")
return value
class Chat(BaseModel):
id: UUID
title: str
member_ids: list[UUID]
created_at: datetime
class ChatPage(BaseModel):
items: list[Chat]
next_cursor: str | None
class CreateMessage(BaseModel):
model_config = ConfigDict(extra="forbid")
text: str = Field(
min_length=1,
max_length=4000,
)
@field_validator("text")
@classmethod
def validate_text(cls, value: str) -> str:
if not value.strip():
raise ValueError("Message text must not be blank")
return value
class Message(BaseModel):
id: UUID
chat_id: UUID
sender_id: UUID
text: str
created_at: datetime
class MessagePage(BaseModel):
items: list[Message]
next_cursor: str | None