40 lines
838 B
Python
40 lines
838 B
Python
from datetime import datetime
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
|
|
|
|
class RoleOut(BaseModel):
|
|
id: int
|
|
name: str
|
|
description: str | None = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
username: str = Field(..., min_length=3, max_length=100)
|
|
email: EmailStr
|
|
password: str = Field(..., min_length=8)
|
|
role_id: int = 3 # default: user
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
username: str | None = Field(None, min_length=3, max_length=100)
|
|
email: EmailStr | None = None
|
|
is_active: bool | None = None
|
|
role_id: int | None = None
|
|
|
|
|
|
class UserOut(BaseModel):
|
|
id: int
|
|
username: str
|
|
email: str
|
|
role_id: int
|
|
is_active: bool
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class UserWithRole(UserOut):
|
|
role: RoleOut
|