feat(api): 实现三端统一的JSON API响应契约

- 新增`api_response.py`统一响应封装工具类,提供标准成功/错误响应构造方法
- 重构WonderQ-Admin全局异常处理器,将所有异常转换为标准响应格式
- 修改所有公共和管理端接口的返回逻辑,统一使用`code`(与HTTP状态码一致)、`msg`和`data`的三层结构
- 新增`api-response-contract.md`文档,定义完整的三端统一JSON响应规范
- 更新所有领域API文档,明确业务数据需位于`data`字段内,补充响应格式说明
- 为WonderQ-MiniAPP和WonderQ-Admin-UI新增响应解析逻辑和类型定义,自动完成协议校验和错误处理
- 更新所有测试用例,适配新的响应结构确保接口符合契约要求
- 新增`module-config-api.md`模块配置API文档,补充站点模块配置的接口约定
- 更新项目README文档,调整文档分类顺序将响应契约置于首位
This commit is contained in:
duanshuwen committed 2026-08-19 22:02:20 +08:00
1 parent d16924584c
commit e082bd2d98
28 files changed
+993 -383

No files matched your search

+6 -2
View File
@@ -142,6 +142,9 @@ def test_public_detail_returns_frontend_contract_without_auth():
assert response.status_code == 200
assert response.json() == {
"code": 200,
"msg": "success",
"data": {
"key": "family-water",
"eyebrow": "玩法推荐",
"duration": "5天4晚",
@@ -153,6 +156,7 @@ def test_public_detail_returns_frontend_contract_without_auth():
"excluded": ["往返大交通"],
"notes": ["请准备轻便雨具。"],
"gallery": ["https://example.test/family-water.jpg"],
},
}
@@ -193,7 +197,7 @@ def test_admin_detail_list_includes_inactive_records():
app.dependency_overrides.clear()
assert response.status_code == 200
assert response.json()["details"][0]["isActive"] is False
assert response.json()["data"]["details"][0]["isActive"] is False
def test_admin_detail_create_normalizes_key_and_appends():
@@ -221,5 +225,5 @@ def test_admin_detail_create_normalizes_key_and_appends():
app.dependency_overrides.clear()
assert response.status_code == 201
assert response.json()["key"] == "family-water"
assert response.json()["data"]["key"] == "family-water"
assert fake_db.added[0].sortOrder == 3