Files
fastapi-best-architecture/backend/app/admin/schema/user.py
T
Wu Clan 7553ccf14d Update return schema of query interface (#492)
* Update return model of query interface

* Update tree data return type hints

* Update code generation and task return types

* Fix inconsistency between ORM query result and schema
2025-01-18 23:33:37 +08:00

103 lines
2.5 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
from pydantic import ConfigDict, EmailStr, Field, HttpUrl, model_validator
from typing_extensions import Self
from backend.app.admin.schema.dept import GetDeptDetail
from backend.app.admin.schema.role import GetRoleDetail
from backend.common.enums import StatusType
from backend.common.schema import CustomPhoneNumber, SchemaBase
class AuthSchemaBase(SchemaBase):
username: str
password: str | None
class AuthLoginParam(AuthSchemaBase):
captcha: str
class RegisterUserParam(AuthSchemaBase):
nickname: str | None = None
email: EmailStr = Field(examples=['user@example.com'])
class AddUserParam(AuthSchemaBase):
dept_id: int
roles: list[int]
nickname: str | None = None
email: EmailStr = Field(examples=['user@example.com'])
class UserInfoSchemaBase(SchemaBase):
dept_id: int | None = None
username: str
nickname: str
email: EmailStr = Field(examples=['user@example.com'])
phone: CustomPhoneNumber | None = None
class UpdateUserParam(UserInfoSchemaBase):
pass
class UpdateUserRoleParam(SchemaBase):
roles: list[int]
class AvatarParam(SchemaBase):
url: HttpUrl = Field(description='头像 http 地址')
class GetUserInfoNoRelationDetail(UserInfoSchemaBase):
model_config = ConfigDict(from_attributes=True)
dept_id: int | None = None
id: int
uuid: str
avatar: str | None = None
status: StatusType = Field(default=StatusType.enable)
is_superuser: bool
is_staff: bool
is_multi_login: bool
join_time: datetime = None
last_login_time: datetime | None = None
class GetUserInfoDetail(GetUserInfoNoRelationDetail):
model_config = ConfigDict(from_attributes=True)
dept: GetDeptDetail | None = None
roles: list[GetRoleDetail]
class GetCurrentUserInfoDetail(GetUserInfoDetail):
model_config = ConfigDict(from_attributes=True)
dept: GetDeptDetail | str | None = None
roles: list[GetRoleDetail] | list[str] | None = None
@model_validator(mode='after')
def handel(self) -> Self:
"""处理部门和角色"""
dept = self.dept
if dept:
self.dept = dept.name # type: ignore
roles = self.roles
if roles:
self.roles = [role.name for role in roles] # type: ignore
return self
class CurrentUserIns(GetUserInfoDetail):
model_config = ConfigDict(from_attributes=True)
class ResetPasswordParam(SchemaBase):
old_password: str
new_password: str
confirm_password: str