Files
digital-psychology/docs/BACKEND_DESIGN/BD-2026-011-identity-home-profile.md
T
jackyu66gitandCursor 13860bf1ef
ci / h5 (push) Canceled after 0s
ci / api (push) Canceled after 0s
ci / ess-docs (push) Canceled after 0s
feat(ECR-011): 昵称、首页贴士与档案 Self 唯一/合盘交叉校验
每账号仅一条 self(migration 40902);合盘只选 TA;账号昵称可改;首页穿衣/颜色/养生贴士。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-12 22:05:00 +08:00

78 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# BD-2026-011 — Identity · Home tips · Profile integrity
Status: Approved
**ECR:** ECR-011
**Date:** 2026-08-12
**Approved:** 2026-08-12(随 ECR-011 Human Approve
**Change Level:** L2
**Risk:** Medium
## Context
- 问题:重复 self;合盘/档案展示不一致;缺昵称与首页贴士契约门禁
- 非目标:社交关系链、真推送、医疗建议
- Specprofile · star-profile · account-auth · home
## Backend Change Boundary
### In
| Area | Change |
|------|--------|
| Migration | `000017`:软删 rn>1 的 self`UNIQUE (user_id) WHERE relation='self' AND deleted_at IS NULL` |
| nickname | `internal/nickname`100×100 词库 · Random · Normalize |
| auth | 注册/回填空昵称;`UpdateNickname``PATCH /auth/me` → 40902 语义外的校验错误用既有码 |
| profile | `CountActiveSelf`Create self 已存在 → `ErrSelfExists` → HTTP 409 / code 40902 |
| report | `CreateSynastry`:同 id 拒绝;本账号 B 须 `other`;附近仍允许他人 geo-visible self |
| home | `GET /home/daily-tips`:生日+本地时 → yijing seed → DeepSeek JSON;失败回退 |
| OpenAPI | `/auth/me` PATCH · `/home/daily-tips` |
### Out
- Handler 直连 DB · 新外部依赖(除既有 DeepSeek)· 硬删 profiles
### Ownership
| Layer | Owner |
|-------|--------|
| Repository | AuthRepo · ProfileRepo |
| Service | auth · profile · home · report |
| Handler | AuthHandler · ProfileHandler · HomeHandler |
| UI | user-h5 Profile / Home / Synastry / Portrait·Star·Rhythm·Cards |
## Architecture Change
- 分层边界:No(无需新 ADR)
- 受影响层:API · Application · Infrastructure(migration) · H5
## Data Flow
```text
Register/Login → nick empty? → nickname.Random → users.nickname
PATCH /auth/me → Normalize → UpdateNickname
POST /profiles self → CountActiveSelf>0? 409 : Insert
GET /profiles → ListH5 用 ensure* / pickable 过滤)
POST /reports/synastry → A owned · B other|nearby self
GET /home/daily-tips → Self birth? → seed → LLM|fallback → tips JSON
```
## Failure / Rollback
- down`DROP INDEX idx_profiles_one_self_per_user`(不自动恢复已软删行)
- LLM 失败:返回 `source=fallback`HTTP 仍 200
- 40902:前端 ensureSelf 捕获后改走 update
## Test Strategy
- go`internal/nickname` · profile Create 冲突(integration 或 service
- H5Synastry 隐藏重复 self · ImageCard/Portrait 经 ensureSelf · Profile 昵称卡
- 手工:档案仅 1 个我;合盘 TA 无多个我;改昵称首页同步;贴士有/无生日
## Rollback plan
1. 回滚应用版本;保留 migration 索引(安全)或执行 down(仅删索引)
2. 关闭 DeepSeek 配置 → 贴士自动 fallback