feat(#1718): PATCH /auth/me 资料更新接口 + profile_completed 字段 #1728

Merged
auto-approve-bot merged 2 commits from feature/patch-me-profile-1718 into develop 2026-09-06 12:06:59 +08:00
Owner

背景

微信新用户昵称引导页(WechatOnboarding.tsx)点"进入小虾智剪"调 PATCH /api/v1/auth/me 返回 405;后端只有 GET /me 没有更新接口,个人设置页改昵称也走同一接口同样损坏。

改动

  • 新增 PATCH /auth/me(仅接受 display_name),strip + 1-20 字符校验,空白/超长 422,前端 UpdateProfileResponse 期望的 {user: {...}} 结构
  • 新增 users.profile_completed 字段(迁移 068):
    • 存量用户默认 True(不触发引导)
    • 微信新建用户在 WechatSyncUseCase._create_wechat_user 内置 False,首次进入 WechatOnboarding 完成设置后置 True
    • GET /me 响应 + PATCH /me 响应都带上该字段,前端 normalizeUser 直接消费
  • /auth/wechat/bind/auth/wechat/unbind 的 user 字段也同步带 profile_completed

测试

  • 12 个新单测(display_name 校验、更新落库、幂等、profile_completed 状态切换、GET /me 字段、依赖声明、微信建号默认 False)
  • 全量 14392 passed(5 个已知 h2 TTS 沙箱失败与本 PR 无关),diff coverage 97%

兼容

  • PATCH /me 是新路由,不影响 GET /me
  • profile_completed 字段为 Boolean 默认 True,存量数据 server_default=1,前端无改动即可正常工作
## 背景 微信新用户昵称引导页(WechatOnboarding.tsx)点"进入小虾智剪"调 PATCH /api/v1/auth/me 返回 405;后端只有 GET /me 没有更新接口,个人设置页改昵称也走同一接口同样损坏。 ## 改动 - 新增 `PATCH /auth/me`(仅接受 display_name),strip + 1-20 字符校验,空白/超长 422,前端 UpdateProfileResponse 期望的 `{user: {...}}` 结构 - 新增 `users.profile_completed` 字段(迁移 068): - 存量用户默认 True(不触发引导) - 微信新建用户在 `WechatSyncUseCase._create_wechat_user` 内置 False,首次进入 WechatOnboarding 完成设置后置 True - GET /me 响应 + PATCH /me 响应都带上该字段,前端 normalizeUser 直接消费 - `/auth/wechat/bind` 与 `/auth/wechat/unbind` 的 user 字段也同步带 profile_completed ## 测试 - 12 个新单测(display_name 校验、更新落库、幂等、profile_completed 状态切换、GET /me 字段、依赖声明、微信建号默认 False) - 全量 14392 passed(5 个已知 h2 TTS 沙箱失败与本 PR 无关),diff coverage 97% ## 兼容 - PATCH /me 是新路由,不影响 GET /me - profile_completed 字段为 Boolean 默认 True,存量数据 server_default=1,前端无改动即可正常工作
xiaoxia added 1 commit 2026-09-06 11:34:52 +08:00
feat(#1718): PATCH /auth/me 资料更新接口(微信新用户昵称设置阻断修复)
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
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 / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped 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 / PR Build API Image (pull_request) Successful in 32s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 31s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 42s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 1m3s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m21s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 1m58s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m50s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 3m43s
AI Code Review / AI Code Review (pull_request) Successful in 6m20s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 8m28s
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) Failing after 1s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 5m44s
2220492611
- 新增 PATCH /auth/me(仅接受 display_name),strip+1-20字符校验,空白/超长422
- users 表加 profile_completed 字段(迁移 068);存量默认 True;微信新建用户在 wechat_sync 内置 False
- /auth/me GET/PATCH 响应均含 profile_completed 字段,前端 normalizeUser 直接消费
- 微信绑定/解绑接口响应同步带 profile_completed
- 12 个新单测,diff coverage 97%

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1728 | | 预览链接 | [https://pr-1728.preview.xiaoxiajianji.com](https://pr-1728.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia added 1 commit 2026-09-06 11:59:20 +08:00
fix(#1718): PostgreSQL boolean default — 用 server_default='true' 替代 '1'
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
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 / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped 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 / PR Build API Image (pull_request) Successful in 35s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 37s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m22s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 1m33s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m53s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 2m19s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m54s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 4m21s
AI Code Review / AI Code Review (pull_request) Failing after 5m35s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 6m53s
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 / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 3s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 4m41s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 9s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 26s
18223dd5fc
Collaborator

【阻塞级判定】

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

📊 审查概览

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

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

  1. [apps/api/app/api/routes/auth.py: 2] from __future__ 导入位置错误
    • 问题类型:语法错误/规范违反
    • 问题描述:根据 Python 语言规范(PEP 236),from __future__ import annotations 语句必须物理上位于模块的最开始,在任何其他代码(包括模块文档字符串 """)之前。当前代码将其插在文档字符串之后,这会导致该指令被 Python 解析器忽略,无法实现“延迟求值类型注解”的预期效果,属于结构性语法错误。
    • 修改建议:将 from __future__ import annotations 移动到文件第一行(在文档字符串 """ 之前)。

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

  1. [apps/api/app/api/routes/auth.py: 306] 冗余的数据库查询
    • 具体内容:在 update_current_user_profile 函数中,user_repository.save(user) 执行后,代码立即调用了 user_repository.find_by_id(user.id) 重新查询用户。实际上,传入的领域实体 user 在第 301-303 行已经在内存中更新了属性(display_nameprofile_completed),save 方法仅负责持久化而不改变传入对象的状态。因此直接使用 user 构造返回响应即可,无需额外的数据库查询,建议删除 fresh = ... 这一行,直接返回 UpdateProfileResponse(user=_user_profile(user))

良好实践

  1. 数据兼容性处理:在 Alembic 迁移和 SQLAlchemy Model 中均正确配置了 server_default="true"default=True,确保了存量数据的兼容性和新数据的默认值正确。
  2. 参数校验严谨UpdateProfileRequest 使用 Pydantic field_validator 对昵称进行了 strip() 处理,并正确校验了空白字符串和长度边界,有效防止了脏数据。
  3. 测试覆盖充分:新增的单元测试覆盖了正常流程、边界值(空格、超长)、幂等性以及响应结构完整性,测试质量较高。

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

### 【阻塞级判定】 - 是否存在阻塞级问题:是 - 阻塞级问题数量:1 个 ### 📊 审查概览 - 整体评价:需修改 - 建议级问题数量:1 个 ### 🔴 阻塞级问题(必须修复) 1. **[apps/api/app/api/routes/auth.py: 2] `from __future__` 导入位置错误** - 问题类型:语法错误/规范违反 - 问题描述:根据 Python 语言规范(PEP 236),`from __future__ import annotations` 语句必须物理上位于模块的最开始,在任何其他代码(包括模块文档字符串 `"""`)之前。当前代码将其插在文档字符串之后,这会导致该指令被 Python 解析器忽略,无法实现“延迟求值类型注解”的预期效果,属于结构性语法错误。 - 修改建议:将 `from __future__ import annotations` 移动到文件第一行(在文档字符串 `"""` 之前)。 ### 💡 改进建议(不阻塞合并) 1. **[apps/api/app/api/routes/auth.py: 306] 冗余的数据库查询** - 具体内容:在 `update_current_user_profile` 函数中,`user_repository.save(user)` 执行后,代码立即调用了 `user_repository.find_by_id(user.id)` 重新查询用户。实际上,传入的领域实体 `user` 在第 301-303 行已经在内存中更新了属性(`display_name` 和 `profile_completed`),`save` 方法仅负责持久化而不改变传入对象的状态。因此直接使用 `user` 构造返回响应即可,无需额外的数据库查询,建议删除 `fresh = ...` 这一行,直接返回 `UpdateProfileResponse(user=_user_profile(user))`。 ### ✅ 良好实践 1. **数据兼容性处理**:在 Alembic 迁移和 SQLAlchemy Model 中均正确配置了 `server_default="true"` 和 `default=True`,确保了存量数据的兼容性和新数据的默认值正确。 2. **参数校验严谨**:`UpdateProfileRequest` 使用 Pydantic `field_validator` 对昵称进行了 `strip()` 处理,并正确校验了空白字符串和长度边界,有效防止了脏数据。 3. **测试覆盖充分**:新增的单元测试覆盖了正常流程、边界值(空格、超长)、幂等性以及响应结构完整性,测试质量较高。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-09-06 04:04:57 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
auto-approve-bot merged commit 528f56254d into develop 2026-09-06 12:06:59 +08:00
auto-approve-bot deleted branch feature/patch-me-profile-1718 2026-09-06 12:06:59 +08:00

🗑️ 预览环境已清理

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

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

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