feat: 用户管理

This commit is contained in:
zy7y
2022-09-15 17:29:15 +08:00
parent fc8632b16e
commit 62c647c1f2
15 changed files with 356 additions and 71 deletions

View File

@@ -48,10 +48,10 @@ async def user_arr(
async def user_list(query: UserQuery) -> Response[ListAll[list[UserRead]]]:
"""post查询用户列表"""
limit = query.size
skip = (query.offset - 1) * limit
del query.offset, query.size
users, count = await get_users(skip, limit, query.dict())
size = query.limit
skip = (query.offset - 1) * size
del query.offset, query.limit
users, count = await get_users(skip, size, query.dict())
return Response(data=ListAll(total=count, items=users))

View File

@@ -63,9 +63,8 @@ async def get_users(skip: int, limit: int, kwargs: dict = None):
kwargs = {f"{k}__contains": v for k, v in kwargs.items()}
else:
kwargs = {}
result = (
UserModel.filter(status__not_in=[9, 5], **kwargs).all().order_by("-created")
)
result = UserModel.filter(**kwargs).all().order_by("-created")
print(await result.offset(skip).limit(limit))
return await result.offset(skip).limit(limit), await result.count()
@@ -98,9 +97,11 @@ async def put_user(uid: int, data: UserPut):
for role in roles:
if await get_role({"id": role.rid, "status__not": 9}) is None:
return role.rid
# 更新用户
data.password = get_password_hash(data.password)
if data.password != "加密之后的密码":
data.password = get_password_hash(data.password)
else:
del data.password
await UserModel.filter(id=uid).update(**data.dict())
# todo 1. 先前有的角色,这次更新成没有 2. 先前没有的角色 这次更新成有, 3. 只更新了状态

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -42,7 +42,7 @@ class QueryData(BaseModel):
"""分页查询基础数据"""
offset: int = 1
size: int = 10
limit: int = 10
class ListAll(GenericModel, Generic[T]):