fix: 修复标题库新建/编辑功能 — 前后端字段名不匹配导致422 #90

Merged
xiaoxia merged 1 commits from fix/p0-create-titles-assets into develop 2026-06-28 21:39:32 +08:00
Owner

问题

v0.1.73 浏览器测试发现 P0:「新建标题」点击确定无反应,modal 不关闭,数据不保存。

根因

前端 api/titles.ts 发送 { content, category } 但后端 CreateTitleLibraryRequest 期望 { name (必填), text (必填), category }。字段名不匹配导致 Pydantic 校验失败返回 422。

修复

  • api/titles.ts: 请求时将 content 映射为后端的 text + 自动截取 name
  • api/titles.ts: 响应时将后端 text 字段映射回前端 content
  • api/titles.ts: updateTitle 改用 PUT(后端实际 HTTP 方法)
  • 页面代码(TitleLibrary.tsx)无需改动,映射在 API 层透明处理

注意

「新建素材库」P0 问题是后端 schema 问题(CreateAssetLibraryRequest 仍要求 project_id,但扁平化架构已无项目概念),需 @后端编程 修复后端 schema。详见调查结论。

Closes #90

## 问题 v0.1.73 浏览器测试发现 P0:「新建标题」点击确定无反应,modal 不关闭,数据不保存。 ## 根因 前端 `api/titles.ts` 发送 `{ content, category }` 但后端 `CreateTitleLibraryRequest` 期望 `{ name (必填), text (必填), category }`。字段名不匹配导致 Pydantic 校验失败返回 422。 ## 修复 - `api/titles.ts`: 请求时将 `content` 映射为后端的 `text` + 自动截取 `name` - `api/titles.ts`: 响应时将后端 `text` 字段映射回前端 `content` - `api/titles.ts`: `updateTitle` 改用 PUT(后端实际 HTTP 方法) - 页面代码(`TitleLibrary.tsx`)无需改动,映射在 API 层透明处理 ## 注意 「新建素材库」P0 问题是后端 schema 问题(`CreateAssetLibraryRequest` 仍要求 `project_id`,但扁平化架构已无项目概念),需 @后端编程 修复后端 schema。详见调查结论。 Closes #90
xiaoxia added 1 commit 2026-06-28 21:29:31 +08:00
fix: 修复标题库新建/编辑功能 — 前后端字段名不匹配导致422
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
54cbfe2adf
根因:前端发送 { content, category } 但后端 CreateTitleLibraryRequest
期望 { name (必填), text (必填), category }。字段名不匹配导致
Pydantic 校验失败返回 422,modal 不关闭,数据不保存。

修复:
- api/titles.ts: 请求时将 content 映射为 text + 自动截取 name
- api/titles.ts: 响应时将后端 text 字段映射回前端 content
- api/titles.ts: updateTitle 改用 PUT(后端实际方法)
- 页面代码无需改动,映射在 API 层透明处理

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
xiaoxia merged commit 2ee3992a94 into develop 2026-06-28 21:39:32 +08:00
Sign in to join this conversation.