c50ccd258f
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests style: 为Java类添加文档注释 docs: 更新.gitignore和配置文件 test: 添加性能测试和Playwright测试脚本 chore: 清理旧测试文件和配置
71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
"""
|
|
通知公告API封装
|
|
"""
|
|
|
|
from typing import Dict, Any
|
|
from httpx import AsyncClient
|
|
|
|
|
|
class SysNoticeAPI:
|
|
"""系统公告API"""
|
|
|
|
def __init__(self, client: AsyncClient):
|
|
self.client = client
|
|
self.base_path = "/api/notices"
|
|
|
|
async def get_all(self) -> Any:
|
|
"""获取所有公告"""
|
|
return await self.client.get(self.base_path)
|
|
|
|
async def get_by_id(self, notice_id: int) -> Any:
|
|
"""根据ID获取公告"""
|
|
return await self.client.get(f"{self.base_path}/{notice_id}")
|
|
|
|
async def get_by_status(self, status: str) -> Any:
|
|
"""根据状态获取公告"""
|
|
return await self.client.get(f"{self.base_path}/status/{status}")
|
|
|
|
async def create(self, data: Dict[str, Any]) -> Any:
|
|
"""创建公告"""
|
|
return await self.client.post(self.base_path, json=data)
|
|
|
|
async def update(self, notice_id: int, data: Dict[str, Any]) -> Any:
|
|
"""更新公告"""
|
|
return await self.client.put(f"{self.base_path}/{notice_id}", json=data)
|
|
|
|
async def delete(self, notice_id: int) -> Any:
|
|
"""删除公告"""
|
|
return await self.client.delete(f"{self.base_path}/{notice_id}")
|
|
|
|
|
|
class SysMessageAPI:
|
|
"""用户消息API"""
|
|
|
|
def __init__(self, client: AsyncClient):
|
|
self.client = client
|
|
self.base_path = "/api/messages"
|
|
|
|
async def get_by_user(self, user_id: int) -> Any:
|
|
"""获取用户所有消息"""
|
|
return await self.client.get(f"{self.base_path}/user/{user_id}")
|
|
|
|
async def get_unread_count(self, user_id: int) -> Any:
|
|
"""获取未读消息数量"""
|
|
return await self.client.get(f"{self.base_path}/user/{user_id}/unread")
|
|
|
|
async def get_unread_list(self, user_id: int) -> Any:
|
|
"""获取未读消息列表"""
|
|
return await self.client.get(f"{self.base_path}/user/{user_id}/unread/list")
|
|
|
|
async def create(self, data: Dict[str, Any]) -> Any:
|
|
"""创建消息"""
|
|
return await self.client.post(self.base_path, json=data)
|
|
|
|
async def mark_as_read(self, message_id: int) -> Any:
|
|
"""标记消息为已读"""
|
|
return await self.client.put(f"{self.base_path}/{message_id}/read")
|
|
|
|
async def delete(self, message_id: int) -> Any:
|
|
"""删除消息"""
|
|
return await self.client.delete(f"{self.base_path}/{message_id}")
|