feat: Phase 2 订阅管理后端 API #78

Merged
xiaoxia merged 3 commits from feat/phase2-subscription-api into develop 2026-06-28 18:35:41 +08:00
Owner

实现 Phase 2 订阅管理后端 API,匹配前端 subscription.ts 接口定义。

实现的端点

  • GET /api/v1/subscription/current — 获取当前订阅信息
  • GET /api/v1/subscription/billing-records — 获取账单记录
  • POST /api/v1/subscription/change-plan — 变更订阅套餐
  • POST /api/v1/subscription/cancel — 取消订阅
  • POST /api/v1/subscription/toggle-auto-renew — 切换自动续费

新增文件

  • apps/api/app/schemas/subscription.py — Pydantic 请求/响应模型
  • apps/api/app/api/routes/subscription.py — 5 个 API 端点

修改文件

  • apps/api/app/api/router.py — 注册 subscription 路由
实现 Phase 2 订阅管理后端 API,匹配前端 subscription.ts 接口定义。 ## 实现的端点 - GET /api/v1/subscription/current — 获取当前订阅信息 - GET /api/v1/subscription/billing-records — 获取账单记录 - POST /api/v1/subscription/change-plan — 变更订阅套餐 - POST /api/v1/subscription/cancel — 取消订阅 - POST /api/v1/subscription/toggle-auto-renew — 切换自动续费 ## 新增文件 - apps/api/app/schemas/subscription.py — Pydantic 请求/响应模型 - apps/api/app/api/routes/subscription.py — 5 个 API 端点 ## 修改文件 - apps/api/app/api/router.py — 注册 subscription 路由
xiaoxia added 1 commit 2026-06-28 17:42:59 +08:00
feat: implement Phase 2 subscription management API
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
27303e34eb
Implement 5 subscription endpoints matching frontend subscription.ts:

API Endpoints:
- GET /api/v1/subscription/current — get current subscription info
- GET /api/v1/subscription/billing-records — get billing history
- POST /api/v1/subscription/change-plan — upgrade/downgrade plan
- POST /api/v1/subscription/cancel — cancel subscription
- POST /api/v1/subscription/toggle-auto-renew — toggle auto-renewal

Implementation Details:
- Created subscription schemas (SubscriptionInfo, BillingRecord, etc.)
- Created subscription routes with proper authentication
- Integrated with quota_registry for plan limits
- Added plan validation (free/standard/pro/enterprise)
- Added billing cycle validation (monthly/yearly)
- Registered subscription router in api_router

Note: Billing records currently returns empty list (TODO: implement billing system)
Auto-renew toggle is simulated (TODO: add auto_renew field to User model)

All endpoints follow existing patterns from titles/voices/duplication APIs.
xiaoxia added 1 commit 2026-06-28 18:26:03 +08:00
fix: 修复订阅API的3个P0问题
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
06f0b9cc46
P0-1: 修复错误的导入路径
  - from app.database import get_db → from app.dependencies import get_user_repository
  - 移除不存在的 Session 依赖

P0-2: 修复直接修改 dataclass 的问题
  - 使用 dataclasses.replace() 创建新实例
  - 通过 UserRepository.save() 持久化更改
  - 更新 UserRepository 以支持订阅字段的读写

P0-3: 移除不存在的 quota_registry 模块
  - 硬编码配额定义 PLAN_QUOTAS
  - free: 3项目/10GB, standard: 10项目/50GB
  - pro: 无限项目/100GB, enterprise: 无限项目/1000GB

额外:
- 添加支付验证 TODO 注释(方案C)
- 更新 UserRepository.save() 保存订阅相关字段
- 更新 UserRepository._to_entity() 读取订阅相关字段
xiaoxia added 1 commit 2026-06-28 18:32:16 +08:00
security: 升级 python-multipart 0.0.12 → 0.0.32 修复 CVE
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
f92bd25583
- CVE-2024-53981 (DoS)
- CVE-2026-24486 (RCE)
xiaoxia merged commit a55a30b085 into develop 2026-06-28 18:35:41 +08:00
Sign in to join this conversation.