feat: 封面模板 CRUD API #1323

Merged
auto-approve-bot merged 3 commits from feat/cover-templates-crud-api into develop 2026-08-09 18:26:00 +08:00
Owner

变更内容

新增封面模板 CRUD API,对接前端封面设置 UI 改造。

API 接口

  • GET /api/v1/cover-templates — 列出系统模板 + 用户自定义模板
  • POST /api/v1/cover-templates — 创建自定义模板
  • PUT /api/v1/cover-templates/{id} — 更新模板(系统模板不可改)
  • DELETE /api/v1/cover-templates/{id} — 删除自定义模板(系统模板不可删)

技术实现

  • 领域实体 CoverTemplate(packages/domain/cover_template.py)
  • 仓储接口 + SQLAlchemy 实现 + InMemory 测试实现
  • Schema 对齐前端 CoverTemplate 类型定义
  • Alembic migration 055,含 8 个系统模板 seed 数据
  • 28 个新单测,全量 13704 单测通过

权限控制

  • 系统模板(is_system=true):所有用户可见,但不可修改/删除
  • 用户自定义模板:仅创建者可见,仅创建者可修改/删除
## 变更内容 新增封面模板 CRUD API,对接前端封面设置 UI 改造。 ### API 接口 - `GET /api/v1/cover-templates` — 列出系统模板 + 用户自定义模板 - `POST /api/v1/cover-templates` — 创建自定义模板 - `PUT /api/v1/cover-templates/{id}` — 更新模板(系统模板不可改) - `DELETE /api/v1/cover-templates/{id}` — 删除自定义模板(系统模板不可删) ### 技术实现 - 领域实体 `CoverTemplate`(packages/domain/cover_template.py) - 仓储接口 + SQLAlchemy 实现 + InMemory 测试实现 - Schema 对齐前端 `CoverTemplate` 类型定义 - Alembic migration 055,含 8 个系统模板 seed 数据 - 28 个新单测,全量 13704 单测通过 ### 权限控制 - 系统模板(`is_system=true`):所有用户可见,但不可修改/删除 - 用户自定义模板:仅创建者可见,仅创建者可修改/删除
xiaoxia force-pushed feat/cover-templates-crud-api from ba7434cfec to 0bccd4fb60 2026-08-09 16:52:26 +08:00 Compare

🚀 预览环境已部署

项目 详情
PR号 #1323
预览链接 https://pr-1323.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1323 | | 预览链接 | [https://pr-1323.preview.xiaoxiajianji.com](https://pr-1323.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot approved these changes 2026-08-09 17:00:35 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-08-09 17:00:36 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia added 1 commit 2026-08-09 17:04:18 +08:00
新增 cover_templates 表及完整 CRUD 接口:
- GET    /api/v1/cover-templates       列出系统+用户模板
- POST   /api/v1/cover-templates       创建自定义模板
- PUT    /api/v1/cover-templates/{id}  更新模板(系统模板不可改)
- DELETE /api/v1/cover-templates/{id}  删除自定义模板(系统模板不可删)

技术实现:
- 领域实体 CoverTemplate(packages/domain/cover_template.py)
- 仓储接口 + SQLAlchemy 实现 + InMemory 实现
- Schema 对齐前端 CoverTemplate 类型定义
- Alembic migration 055,含 8 个系统模板 seed 数据
- 28 个新单测,全量 13704 单测通过
xiaoxia force-pushed feat/cover-templates-crud-api from c8779eb8b7 to 70e4d3e537 2026-08-09 17:04:18 +08:00 Compare
xiaoxia added 1 commit 2026-08-09 17:04:55 +08:00
fix: 修复 AI Code Review 阻塞级问题
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 41s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m27s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m27s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m35s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m57s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m45s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m19s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m14s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 3m5s
AI Code Review / AI Code Review (pull_request) Failing after 4m51s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m41s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 7m5s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 5s
54c16765e9
- 迁移 seed 数据 ID 改用 UUID hex 格式,与领域模型一致
- 统一 InMemory 和 SQLAlchemy 排序逻辑(系统模板优先)
xiaoxia force-pushed feat/cover-templates-crud-api from 70e4d3e537 to 54c16765e9 2026-08-09 17:04:55 +08:00 Compare
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:是
  • 阻塞级问题数量:2 个

📊 审查概览

  • 整体评价:需修改
  • 建议级问题数量:2 个

🔴 阻塞级问题(必须修复)

  1. [alembic/versions/055_cover_templates.py: 72] 数据迁移中 JSON 字段处理错误

    • 问题类型:数据损坏风险 / 逻辑bug
    • 问题描述:在预置系统模板数据时,使用了 json.dumps(config) 将字典转换为字符串。由于数据库列定义为 sa.JSON,SQLAlchemy 会自动处理 Python 字典到 JSON 类型的转换。手动 json.dumps 会导致数据库中存储的是 JSON 字符串(如 "{\"key\":\"value\"}")而不是 JSON 对象(如 {"key":"value"})。这会导致应用程序读取数据时得到字符串而非字典,从而引发类型错误或逻辑崩溃。
    • 修改建议:直接传入 config 字典对象,删除 json.dumps() 调用。
  2. [packages/adapters/sqlalchemy_impl/cover_template_repository.py: 19, 55, 73] 仓储层破坏了事务边界

    • 问题类型:数据损坏风险
    • 问题描述:在 createupdatedelete 方法中直接调用了 self.session.commit()。在 FastAPI 结合 SQLAlchemy 的标准实践中,Session 通常由请求作用域的依赖项(如 get_db_session)管理,并在请求结束时统一提交或回滚。在仓储内部提前提交会导致:1. 如果后续业务逻辑抛出异常,已提交的数据无法回滚,造成数据不一致;2. 破坏了 Unit of Work 模式。
    • 修改建议:移除仓储方法中的 self.session.commit(),将事务控制权交由上层的依赖项管理。

💡 改进建议(不阻塞合并)

  1. [apps/api/app/api/routes/cover_templates.py: 20, 47] 依赖注入类型标注缺失

    • 具体内容:路由处理函数中 repo: Any = Depends(...) 使用了 Any 类型。建议将其标注为具体的接口类型 CoverTemplateRepository,以提高代码的可读性和 IDE 的支持度(如自动补全)。
  2. [apps/api/app/api/routes/cover_templates.py: 79] 异常处理不够友好

    • 具体内容:在 update_cover_template 中调用了 repo.update(template),如果该模板在 get 之后被删除(并发场景),仓储层会抛出 ValueError。目前未捕获该异常,FastAPI 会将其处理为 500 Internal Server Error。建议捕获 ValueError 并返回 404 或 400 错误,提升 API 用户体验。

格式检查通过 | 逻辑审查需修改 | ⚠️ 建议关注性能


🤖 由 AI 代码审查机器人自动生成 | 2026-08-09 09:09:48 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:是 - 阻塞级问题数量:2 个 ### 📊 审查概览 - 整体评价:需修改 - 建议级问题数量:2 个 ### 🔴 阻塞级问题(必须修复) 1. **[alembic/versions/055_cover_templates.py: 72] 数据迁移中 JSON 字段处理错误** - 问题类型:数据损坏风险 / 逻辑bug - 问题描述:在预置系统模板数据时,使用了 `json.dumps(config)` 将字典转换为字符串。由于数据库列定义为 `sa.JSON`,SQLAlchemy 会自动处理 Python 字典到 JSON 类型的转换。手动 `json.dumps` 会导致数据库中存储的是 JSON 字符串(如 `"{\"key\":\"value\"}"`)而不是 JSON 对象(如 `{"key":"value"}`)。这会导致应用程序读取数据时得到字符串而非字典,从而引发类型错误或逻辑崩溃。 - 修改建议:直接传入 `config` 字典对象,删除 `json.dumps()` 调用。 2. **[packages/adapters/sqlalchemy_impl/cover_template_repository.py: 19, 55, 73] 仓储层破坏了事务边界** - 问题类型:数据损坏风险 - 问题描述:在 `create`、`update` 和 `delete` 方法中直接调用了 `self.session.commit()`。在 FastAPI 结合 SQLAlchemy 的标准实践中,Session 通常由请求作用域的依赖项(如 `get_db_session`)管理,并在请求结束时统一提交或回滚。在仓储内部提前提交会导致:1. 如果后续业务逻辑抛出异常,已提交的数据无法回滚,造成数据不一致;2. 破坏了 Unit of Work 模式。 - 修改建议:移除仓储方法中的 `self.session.commit()`,将事务控制权交由上层的依赖项管理。 ### 💡 改进建议(不阻塞合并) 1. **[apps/api/app/api/routes/cover_templates.py: 20, 47] 依赖注入类型标注缺失** - 具体内容:路由处理函数中 `repo: Any = Depends(...)` 使用了 `Any` 类型。建议将其标注为具体的接口类型 `CoverTemplateRepository`,以提高代码的可读性和 IDE 的支持度(如自动补全)。 2. **[apps/api/app/api/routes/cover_templates.py: 79] 异常处理不够友好** - 具体内容:在 `update_cover_template` 中调用了 `repo.update(template)`,如果该模板在 `get` 之后被删除(并发场景),仓储层会抛出 `ValueError`。目前未捕获该异常,FastAPI 会将其处理为 500 Internal Server Error。建议捕获 `ValueError` 并返回 404 或 400 错误,提升 API 用户体验。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ⚠️ 建议关注性能 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-09 09:09:48 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia added 1 commit 2026-08-09 18:16:42 +08:00
chore: trigger CI rerun [skip review]
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 44s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 49s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 55s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m23s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m44s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m50s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m49s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m22s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m28s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m15s
AI Code Review / AI Code Review (pull_request) Successful in 6m43s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 6m39s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 6s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 41s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 47s
891af21a25
auto-approve-bot merged commit 153b38a62f into develop 2026-08-09 18:26:00 +08:00
auto-approve-bot deleted branch feat/cover-templates-crud-api 2026-08-09 18:26:01 +08:00

🗑️ 预览环境已清理

PR #1323 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1323 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.