2de0529d34
refactor: 重构日志服务层代码,将分页逻辑移至Repository层 test: 添加日志分页查询的单元测试和组件测试 docs: 更新README文档,记录API响应格式修复过程 chore: 清理无用文件,更新.gitignore配置 build: 添加Jacoco代码覆盖率插件配置 ci: 添加测试环境配置文件application-h2-test.yml style: 统一日志服务代码格式,添加必要的日志输出
51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
"""
|
||
用户管理 API 客户端
|
||
"""
|
||
|
||
from httpx import AsyncClient
|
||
|
||
|
||
class UserAPI:
|
||
"""用户管理 API 客户端"""
|
||
|
||
def __init__(self, client: AsyncClient):
|
||
self.client = client
|
||
|
||
async def get_user_list(self):
|
||
"""获取用户列表"""
|
||
return await self.client.get('/api/users')
|
||
|
||
async def get_users_by_page(self, page: int = 0, size: int = 10, **kwargs):
|
||
"""分页获取用户列表,支持搜索和排序"""
|
||
params = {'page': page, 'size': size}
|
||
params.update(kwargs)
|
||
return await self.client.get('/api/users/page', params=params)
|
||
|
||
async def create_user(self, user_data):
|
||
"""创建用户"""
|
||
return await self.client.post('/api/users', json=user_data)
|
||
|
||
async def get_user_by_id(self, user_id):
|
||
"""根据ID获取用户"""
|
||
return await self.client.get(f'/api/users/{user_id}')
|
||
|
||
async def update_user(self, user_id, user_data):
|
||
"""更新用户"""
|
||
return await self.client.put(f'/api/users/{user_id}', json=user_data)
|
||
|
||
async def delete_user(self, user_id):
|
||
"""删除用户"""
|
||
return await self.client.delete(f'/api/users/{user_id}')
|
||
|
||
async def get_user_profile(self):
|
||
"""获取当前用户资料(调用get_user_by_id,使用token中的userId)"""
|
||
return await self.client.get('/api/users/profile')
|
||
|
||
async def update_user_profile(self, profile_data):
|
||
"""更新当前用户资料(调用update_user,使用token中的userId)"""
|
||
return await self.client.put('/api/users/profile', json=profile_data)
|
||
|
||
async def assign_roles(self, user_id, role_ids):
|
||
"""为用户分配角色"""
|
||
return await self.client.post(f'/api/users/{user_id}/roles', json=role_ids)
|