Skip to content

refactor(server): 按功能拆分 API 路由模块#362

Merged
huan-yp merged 7 commits intoOpenWSGR:mainfrom
yltx:feature/gui-api-enhancements
Mar 11, 2026
Merged

refactor(server): 按功能拆分 API 路由模块#362
huan-yp merged 7 commits intoOpenWSGR:mainfrom
yltx:feature/gui-api-enhancements

Conversation

@yltx
Copy link
Copy Markdown
Contributor

@yltx yltx commented Mar 10, 2026

概述

将原 main.py 中的所有端点按功能拆分为独立路由模块,提高可维护性和问题定位效率。

文件结构

文件 职责
main.py 应用入口、生命周期、CORS、WebSocket、路由注册
outes/system.py 系统管理 /api/system/*
outes/task.py 任务执行 /api/task/*
outes/game.py 游戏状态查询 /api/game/* + /api/expedition/status + /api/build/status
outes/ops.py 操作端点 (远征收取、建造、奖励、烹饪、修理、解装)
outes/health.py 健康检查 /api/health
serializers.py 游戏对象序列化工具函数

新增 API 端点

  • GET /api/game/context增强版,包含资源/舰队/远征/建造完整状态
  • GET /api/expedition/status — 远征槽位状态查询
  • GET /api/build/status — 建造队列状态查询
  • POST /api/build/collect — 收取已完成建造
  • POST /api/build/start — 开始建造
  • POST /api/reward/collect — 收取任务奖励
  • POST /api/cook — 食堂烹饪
  • POST /api/repair/bath — 浴室修理
  • POST /api/destroy — 解装/解体
  • GET /api/health — 服务器健康检查

测试

所有 16 个 REST 端点和 2 个 WebSocket 端点通过 FastAPI TestClient 验证:

  • 无需系统启动的端点 (system/status, task/stop, task/status, health) 返回 200
  • 需要系统启动的端点在未启动时正确返回 503

关联 issue: #360

yltx and others added 7 commits March 9, 2026 19:46
将原 main.py 中的所有端点按功能拆分为独立路由模块:

- routes/system.py: 系统管理 (/api/system/start|stop|status)
- routes/task.py: 任务执行 (/api/task/start|stop|status)
- routes/game.py: 游戏状态查询 (/api/game/context|acquisition, /api/expedition/status, /api/build/status)
- routes/ops.py: 操作端点 (/api/expedition/check, /api/build/collect|start, /api/reward/collect, /api/cook, /api/repair/bath, /api/destroy)
- routes/health.py: 健康检查 (/api/health)
- serializers.py: 游戏对象序列化工具函数

main.py 精简为仅保留: 应用创建、生命周期管理、CORS、WebSocket 端点、路由注册。

新增 API 端点:
- GET /api/game/context: 增强版,包含资源/舰队/远征/建造完整状态
- GET /api/expedition/status: 远征槽位状态查询
- GET /api/build/status: 建造队列状态查询
- POST /api/build/collect: 收取已完成建造
- POST /api/build/start: 开始建造
- POST /api/reward/collect: 收取任务奖励
- POST /api/cook: 食堂烹饪
- POST /api/repair/bath: 浴室修理
- POST /api/destroy: 解装/解体
- GET /api/health: 服务器健康检查

关联 issue: #360
@huan-yp huan-yp merged commit 2dc085a into OpenWSGR:main Mar 11, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants