""" 字典管理API封装 """ from typing import Dict, Any, Optional from httpx import AsyncClient class DictTypeAPI: """字典类型API""" def __init__(self, client: AsyncClient): self.client = client self.base_path = "/api/dict/types" async def get_all(self) -> Any: """获取所有字典类型""" return await self.client.get(self.base_path) async def get_by_id(self, dict_id: int) -> Any: """根据ID获取字典类型""" return await self.client.get(f"{self.base_path}/{dict_id}") async def create(self, data: Dict[str, Any]) -> Any: """创建字典类型""" return await self.client.post(self.base_path, json=data) async def update(self, dict_id: int, data: Dict[str, Any]) -> Any: """更新字典类型""" return await self.client.put(f"{self.base_path}/{dict_id}", json=data) async def delete(self, dict_id: int) -> Any: """删除字典类型""" return await self.client.delete(f"{self.base_path}/{dict_id}") class DictDataAPI: """字典数据API""" def __init__(self, client: AsyncClient): self.client = client self.base_path = "/api/dict/data" async def get_all(self) -> Any: """获取所有字典数据""" return await self.client.get(self.base_path) async def get_by_id(self, data_id: int) -> Any: """根据ID获取字典数据""" return await self.client.get(f"{self.base_path}/{data_id}") async def get_by_type(self, dict_type: str) -> Any: """根据字典类型获取字典数据""" return await self.client.get(f"{self.base_path}/type/{dict_type}") async def create(self, data: Dict[str, Any]) -> Any: """创建字典数据""" return await self.client.post(self.base_path, json=data) async def update(self, data_id: int, data: Dict[str, Any]) -> Any: """更新字典数据""" return await self.client.put(f"{self.base_path}/{data_id}", json=data) async def delete(self, data_id: int) -> Any: """删除字典数据""" return await self.client.delete(f"{self.base_path}/{data_id}")