Commit ff6ea03e authored by xianyang's avatar xianyang

优化角色查询

parent 3c24574c
......@@ -21,7 +21,7 @@ def get_roles(db: Session, param):
if name:
query_res = db.query(models.Role).filter(models.Role.role_name.like(f'%{name}%')).order_by(models.Role.id.desc()).\
offset((int(param.page) - 1) * param.size).limit(param.page * param.size).all()
count = db.query(models.Role).filter(models.Role.role_name.like(f'%{name}%')).scalar()
count = db.query(func.count(models.Role.id)).filter(models.Role.role_name.like(f'%{name}%')).scalar()
else:
query_res = db.query(models.Role).order_by(models.Role.id.desc()).offset((int(param.page) - 1) * param.size).limit(param.size).all()
count = db.query(func.count(models.Role.id)).scalar()
......
......@@ -36,7 +36,7 @@ class HttpResultResponse(Response):
result_dict = {**result_dict, **kwargs}
super().__init__(
content=json.dumps(result_dict,cls=DecimalEncoder),
content=json.dumps(result_dict, cls=DecimalEncoder),
media_type="application/json",
status_code=result_dict.get('code')
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment