refactor:修改pydantic数据校验模型名

This commit is contained in:
zhengxinonly
2022-07-04 20:56:24 +08:00
parent 45874b17ee
commit ad0f174996
8 changed files with 14 additions and 57 deletions
+5 -5
View File
@@ -9,7 +9,7 @@ from extensions import db
from models import DepartmentModel, UserModel
class DeptModel(BaseModel):
class DeptSchema(BaseModel):
address: t.Optional[str]
dept_name: t.Optional[str] = Field(alias='deptName')
email: t.Optional[str]
@@ -59,7 +59,7 @@ class DepartmentsApi(MethodView):
, code=0)
@validate()
def post(self, body: DeptModel):
def post(self, body: DeptSchema):
dept = DepartmentModel(
parent_id=body.parent_id,
dept_name=body.dept_name,
@@ -76,7 +76,7 @@ class DepartmentsApi(MethodView):
return success_api(message="成功")
@validate()
def put(self, _id, body: DeptModel):
def put(self, _id, body: DeptSchema):
data = {
"dept_name": body.dept_name,
"sort": body.sort,
@@ -88,9 +88,9 @@ class DepartmentsApi(MethodView):
}
body = DepartmentModel.query.filter_by(id=_id).update(data)
if not body:
return fail_api(message="更新失败")
return {'success': False, 'message': "更新失败", 'code': 404}
db.session.commit()
return success_api(message="更新成功")
return {'success': True, 'message': '更新成功', 'code': 200}
def delete(self, _id):
ret = DepartmentModel.query.filter_by(id=_id).delete()
+3 -3
View File
@@ -147,7 +147,7 @@ def make_menu_tree():
return sorted(menu_dict.get(0), key=lambda item: item['sort'])
class PowerModel(BaseModel):
class PowerSchema(BaseModel):
icon: str
open_type: Optional[str] = Field(alias='openType')
parent_id: Optional[str] = Field(alias='parentId')
@@ -199,7 +199,7 @@ class RightsApi(MethodView):
class PowerApi(MethodView):
@validate()
def post(self, body: PowerModel):
def post(self, body: PowerSchema):
power = RightModel(
icon=body.icon,
open_type=body.open_type,
@@ -239,7 +239,7 @@ class PowerApi(MethodView):
return fail_api(message="删除失败")
@validate()
def put(self, _id, body: PowerModel):
def put(self, _id, body: PowerSchema):
data = {
"icon": body.icon,
"open_type": body.open_type,