2022-09-12 15:22:18 +00:00
|
|
|
from typing import Optional
|
2022-09-11 10:34:18 +00:00
|
|
|
|
2022-09-12 07:11:12 +00:00
|
|
|
from pydantic import BaseModel, Field
|
2022-09-11 10:34:18 +00:00
|
|
|
|
2022-09-12 15:22:18 +00:00
|
|
|
from schemas.common import QueryData, ReadBase
|
2022-09-11 10:34:18 +00:00
|
|
|
|
|
|
|
|
2022-09-12 15:22:18 +00:00
|
|
|
class UserRole(BaseModel):
|
|
|
|
uid: int = Field(description="用户id")
|
|
|
|
rid: int = Field(description="角色id")
|
|
|
|
|
|
|
|
|
|
|
|
class UserRoleRead(UserRole, ReadBase):
|
|
|
|
"""用户 角色 读取模型"""
|
|
|
|
|
|
|
|
pass
|
2022-09-12 07:11:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserBasic(BaseModel):
|
|
|
|
username: str
|
|
|
|
nickname: str
|
|
|
|
|
|
|
|
|
|
|
|
class UserIn(UserBasic):
|
|
|
|
password: str
|
|
|
|
|
|
|
|
|
|
|
|
class UserRead(UserBasic, ReadBase):
|
|
|
|
pass
|
|
|
|
|
2022-09-11 10:34:18 +00:00
|
|
|
|
2022-09-12 15:22:18 +00:00
|
|
|
class UserHasRole(BaseModel):
|
|
|
|
"""用户拥有角色"""
|
|
|
|
|
|
|
|
id: int
|
|
|
|
name: str
|
|
|
|
status: int = Field(default=1, description="激活角色 5 正常 1 删除 9")
|
|
|
|
|
|
|
|
|
2022-09-11 10:34:18 +00:00
|
|
|
class UserInfo(UserRead):
|
2022-09-12 15:22:18 +00:00
|
|
|
"""用户信息模型"""
|
|
|
|
|
|
|
|
roles: list[UserHasRole] = Field(..., description="用户拥有角色")
|
|
|
|
|
|
|
|
|
|
|
|
class RoleActive(BaseModel):
|
|
|
|
rid: int = Field(description="角色id")
|
|
|
|
status: int = Field(default=1, description="激活角色 5 正常 1 删除 9")
|
2022-09-11 10:34:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserAdd(UserIn):
|
2022-09-12 15:22:18 +00:00
|
|
|
"""新增用户模型"""
|
|
|
|
|
|
|
|
rids: list[RoleActive] = Field(..., description="选择角色列表")
|
2022-09-11 10:34:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserQuery(QueryData):
|
2022-09-12 15:22:18 +00:00
|
|
|
"""查询模型"""
|
|
|
|
|
2022-09-11 10:34:18 +00:00
|
|
|
username: Optional[str] = Field("", description="用户名")
|
|
|
|
nickname: Optional[str] = Field("", description="姓名")
|
|
|
|
|
|
|
|
|
2022-09-12 15:22:18 +00:00
|
|
|
class UserPut(BaseModel):
|
|
|
|
"""用户更新模型"""
|
|
|
|
|
|
|
|
nickname: str = Field(..., description="用户昵称")
|
|
|
|
password: str = Field(..., description="密码")
|
|
|
|
rids: list[RoleActive] = Field(..., description="选择角色列表")
|