30 lines
862 B
Python
30 lines
862 B
Python
from uuid import UUID
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
|
|
|
|
from utils.dates import UtcDatetime
|
|
|
|
|
|
class CreateUserRequest(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
username: StrictStr = Field(pattern=r"^[a-z0-9_]{3,32}$")
|
|
display_name: StrictStr = Field(min_length=1, max_length=100)
|
|
password: StrictStr = Field(min_length=12, max_length=128)
|
|
|
|
@field_validator("display_name")
|
|
def validate_display_name(cls, v):
|
|
if not v.strip():
|
|
raise ValueError("display_name must not be blank")
|
|
return v
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
# Собирается из ORM-объекта; password_hash сюда не попадает.
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: UUID
|
|
username: str
|
|
display_name: str
|
|
created_at: UtcDatetime
|