47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
username: str = Field(min_length=1, max_length=64)
|
|
nickname: str | None = None
|
|
email: EmailStr | None = None
|
|
dept_id: int | None = None
|
|
status: str = Field(default="ACTIVE", pattern=r"^(ACTIVE|DISABLED)$")
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
password: str = Field(min_length=6, max_length=128)
|
|
role_ids: list[int] = Field(default_factory=list)
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
nickname: str | None = None
|
|
email: EmailStr | None = None
|
|
dept_id: int | None = None
|
|
status: str | None = Field(default=None, pattern=r"^(ACTIVE|DISABLED)$")
|
|
role_ids: list[int] | None = None
|
|
|
|
|
|
class UserResetPwd(BaseModel):
|
|
password: str = Field(min_length=6, max_length=128)
|
|
|
|
|
|
class UserBrief(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
username: str
|
|
nickname: str | None = None
|
|
status: str
|
|
is_superuser: bool = False
|
|
|
|
|
|
class UserRead(UserBrief):
|
|
email: str | None = None
|
|
dept_id: int | None = None
|
|
dept_name: str | None = None
|
|
role_ids: list[int] = Field(default_factory=list)
|
|
role_names: list[str] = Field(default_factory=list)
|