Реализовал уровень 3: PostgreSQL, пароли и сохраняемые сессии
This commit is contained in:
+11
-3
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
|
||||
@@ -36,8 +37,9 @@ class User(BaseModel):
|
||||
|
||||
class CreateUser(BaseModel):
|
||||
"""Данные для создания пользователя."""
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
model_config = ConfigDict(extra="forbid", strict=True)
|
||||
|
||||
password: str = Field(..., min_length=12, max_length=128)
|
||||
username: str = Field(..., pattern=r"^[a-z0-9_]{3,32}$")
|
||||
display_name: str = Field(..., min_length=1, max_length=100)
|
||||
|
||||
@@ -60,11 +62,17 @@ class Chat(BaseModel):
|
||||
|
||||
class CreateChat(BaseModel):
|
||||
"""Данные для создания чата."""
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
model_config = ConfigDict(extra="forbid", strict=True)
|
||||
|
||||
title: str = Field(..., min_length=1, max_length=100)
|
||||
member_ids: list[str] = Field(..., min_length=1, max_length=100)
|
||||
|
||||
@field_validator("member_ids")
|
||||
@classmethod
|
||||
def valid_members(cls, values):
|
||||
"""Проверить UUID и привести их к единому представлению."""
|
||||
return [str(uuid.UUID(value)) for value in values]
|
||||
|
||||
@field_validator("title")
|
||||
@classmethod
|
||||
def title_not_whitespace_only(cls, v: str) -> str:
|
||||
@@ -85,7 +93,7 @@ class Message(BaseModel):
|
||||
|
||||
class CreateMessage(BaseModel):
|
||||
"""Данные для отправки сообщения."""
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
model_config = ConfigDict(extra="forbid", strict=True)
|
||||
|
||||
text: str = Field(..., min_length=1, max_length=4000)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user