async def create_user(user_in: UserCreate, pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 添加用户 """ user = await crud_user.create(pgdvm=pgdb, obj_in=user_in) return m2d(user)
async def read_users( query: str = Query( None, title='搜索关键字', description='模糊查询匹配(用户名, 昵称, 邮箱和电话)'), pgdb=Depends(depends_db), current_user=Depends(get_current_user), ): lst = await crud_user.get_multi(pgdvm=pgdb, querykey=query) return m2d(lst)
async def create_role(obj_in: RoleCreate, pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 添加角色 """ obj = await crud_role.create(pgdvm=pgdb, obj_in=obj_in) return m2d(obj)
async def read_roles( limit: int = Query(100, title="返回数量"), skip: int = Query(0, title="跳过数量"), pgdb=Depends(depends_db), current_user=Depends(get_current_user), ): lst = await crud_role.get_multi(pgdvm=pgdb, skip=skip, limit=limit) return m2d(lst)
async def update_user_me(user_in: UserUpdateMe, pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 获取当前登录用户信息 """ user = await crud_user.get(pgdvm=pgdb, id=current_user['id']) user = await crud_user.update(pgdvm=pgdb, db_obj=user, obj_in=user_in) return m2d(user)
async def user_one(id: int = Path(..., title="ID"), pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 按ID获取信息 """ user = await crud_user.get(pgdvm=pgdb, id=id) logger.info(user.username) logger.info(f'role:{user.role_id}') return m2d(user)
async def user_me(pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 获取当前登录用户信息 """ try: user = await crud_user.get(pgdvm=pgdb, id=current_user['id']) return m2d(user) except Exception as e: logger.error(e)
async def update_role(obj_in: RoleUpdate, id: int = Path(..., title="ID"), pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 编辑角色, 覆盖编辑 """ obj = await crud_role.get(pgdvm=pgdb, id=id) obj = await crud_role.update(pgdvm=pgdb, db_obj=obj, obj_in=obj_in) return m2d(obj)
async def del_user(id: int = Path(..., title="ID"), pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 按ID禁用信息 """ user = await crud_user.get(pgdvm=pgdb, id=id) user_in = UserUpdate(is_active=False) user = await crud_user.update(pgdvm=pgdb, db_obj=user, obj_in=user_in) return m2d(user)
async def update_user(user_in: UserUpdate, id: int = Path(..., title="ID"), pgdb=Depends(depends_db), current_user=Depends(get_current_user)): """ 编辑用户, 覆盖编辑 """ user = await crud_user.get(pgdvm=pgdb, id=id) user = await crud_user.update(pgdvm=pgdb, db_obj=user, obj_in=user_in) return m2d(user)