diff --git a/.ai/product/feature-spec/README.md b/.ai/product/feature-spec/README.md index b992665..ab955d4 100644 --- a/.ai/product/feature-spec/README.md +++ b/.ai/product/feature-spec/README.md @@ -49,6 +49,7 @@ | [ops-image-card-deck.md](ops-image-card-deck.md) | ExploreConfig ImageCardDeck | §7 | `GET /admin/explore/image-card-decks*` | Ops-D · **ECR-037 Closed** | | [ops-report-template.md](ops-report-template.md) | GrowthInsights ReportTemplate | §7 | `GET /admin/growth/report-templates*` | Ops-D · **ECR-038 Closed** | | [ops-funnel-definition.md](ops-funnel-definition.md) | GrowthInsights FunnelDefinition | §7 | `GET /admin/analytics/funnel-definitions*` | Ops-D · **ECR-039 Closed** | +| [ops-scale-definition.md](ops-scale-definition.md) | ExploreConfig ScaleDefinition | §7 | `GET /admin/explore/scales*` | Ops-D · **ECR-040 Closed** | 新功能:复制 `_TEMPLATE.md` → 填满 → 在本表登记 → 再编码。 diff --git a/.ai/product/feature-spec/ops-scale-definition.md b/.ai/product/feature-spec/ops-scale-definition.md new file mode 100644 index 0000000..d053372 --- /dev/null +++ b/.ai/product/feature-spec/ops-scale-definition.md @@ -0,0 +1,41 @@ +# Feature Spec: ExploreConfig · ScaleDefinition(Ops · ECR-040) + +> Status: `Active`(Loop continuous · **ECR-040 Closed**) +> Parent: WAVE0-FROZEN · Predecessor: ECR-039 Closed +> Capability: `ExploreConfig` · BC: `Explore_Reports` +> 授权:`docs/WAVE0/LOOP_AUTHORIZATION.md` + +## Non-goals + +PATCH status(已有 content.write)· 题干编辑 · UGC · 真支付 + +## L2 Domain + +| 概念 | 语义 | +|------|------| +| `ScaleDefinition` | 本切片只读目录;code 唯一(若适用) | + +## L3 API + +| Method | Path | 权限 | 语义 | +|--------|------|------|------| +| GET | `/admin/explore/scales` | `admin.explore.read` | 只读 | +| GET | `/admin/explore/scales/{id}` | `admin.explore.read` | 只读 | + +## Migration + +Migration NO:复用 `scales` 表只读投影 + +## L4 AC + +| ID | Then | +|----|------| +| AC-F-01 | list 含种子或空列表合法 | +| AC-F-02 | 已知 id get 200 | +| AC-F-03 | 未知 id → 404 | +| AC-S-01 | 无 Admin → 401 | +| AC-S-02 | 无权限 → 403 | +| AC-P-01 | list < 500ms | +| AC-O-01 | N/A 只读 | + +contract_diff: `docs/CONTRACT_DIFF/ECR-040.yaml` diff --git a/apps/admin-h5/src/api/client.ts b/apps/admin-h5/src/api/client.ts index 572e2ce..e917777 100644 --- a/apps/admin-h5/src/api/client.ts +++ b/apps/admin-h5/src/api/client.ts @@ -457,6 +457,10 @@ export const adminApi = { request<{ items: Array> }>('GET', '/content-safety/cases'), case: (id: string) => request>('GET', `/content-safety/cases/${id}`), + events: () => + request<{ items: Array> }>('GET', '/crisis/events'), + event: (id: string) => + request>('GET', `/crisis/events/${id}`), interventions: () => request<{ items: Array> }>('GET', '/crisis/interventions'), intervention: (id: string) => @@ -467,7 +471,7 @@ export const adminApi = { request>('GET', `/ask/handoffs/${id}`), requests: () => request<{ items: Array> }>('GET', '/privacy/requests'), - request: (id: string) => + privacyRequest: (id: string) => request>('GET', `/privacy/requests/${id}`), starConfigs: () => request<{ items: Array> }>('GET', '/explore/star-configs'), @@ -489,6 +493,10 @@ export const adminApi = { request<{ items: Array> }>('GET', '/analytics/funnel-definitions'), funnelDefinition: (id: string) => request>('GET', `/analytics/funnel-definitions/${id}`), + exploreScales: () => + request<{ items: Array> }>('GET', '/explore/scales'), + exploreScale: (id: string) => + request>('GET', `/explore/scales/${id}`), orders: () => request<{ items: Array<{ diff --git a/apps/admin-h5/src/layouts/AdminShell.vue b/apps/admin-h5/src/layouts/AdminShell.vue index a2aeab1..e858cf5 100644 --- a/apps/admin-h5/src/layouts/AdminShell.vue +++ b/apps/admin-h5/src/layouts/AdminShell.vue @@ -35,6 +35,7 @@ async function onLogout() { AI 危机 CMS + 目录仓 订单 审计 diff --git a/apps/admin-h5/src/pages/CatalogHubPage.vue b/apps/admin-h5/src/pages/CatalogHubPage.vue new file mode 100644 index 0000000..a8ff7b3 --- /dev/null +++ b/apps/admin-h5/src/pages/CatalogHubPage.vue @@ -0,0 +1,91 @@ + + + + + diff --git a/apps/admin-h5/src/router/index.ts b/apps/admin-h5/src/router/index.ts index e437c29..ad4d625 100644 --- a/apps/admin-h5/src/router/index.ts +++ b/apps/admin-h5/src/router/index.ts @@ -22,6 +22,7 @@ const router = createRouter({ { path: 'ai', name: 'ai', component: () => import('@/pages/AIConfigPage.vue') }, { path: 'crisis', name: 'crisis', component: () => import('@/pages/CrisisPage.vue') }, { path: 'cms', name: 'cms', component: () => import('@/pages/CMSPage.vue') }, + { path: 'catalogs', name: 'catalogs', component: () => import('@/pages/CatalogHubPage.vue') }, { path: 'audit', name: 'audit', component: () => import('@/pages/AuditPage.vue') }, ], }, diff --git a/apps/api/internal/handler/admin.go b/apps/api/internal/handler/admin.go index b980461..f32c931 100644 --- a/apps/api/internal/handler/admin.go +++ b/apps/api/internal/handler/admin.go @@ -68,6 +68,7 @@ func (h *AdminHandler) Register(api *gin.RouterGroup) { h.registerImageCardDecks(authed) h.registerReportTemplates(authed) h.registerFunnelDefinitions(authed) + h.registerExploreScales(authed) } func (h *AdminHandler) Login(c *gin.Context) { diff --git a/apps/api/internal/handler/admin_explore_scales.go b/apps/api/internal/handler/admin_explore_scales.go new file mode 100644 index 0000000..6304677 --- /dev/null +++ b/apps/api/internal/handler/admin_explore_scales.go @@ -0,0 +1,46 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + + "github.com/yuxingu/digital-psychology/apps/api/internal/middleware" + "github.com/yuxingu/digital-psychology/apps/api/internal/service/admin" + "github.com/yuxingu/digital-psychology/apps/api/pkg/response" +) + +func (h *AdminHandler) registerExploreScales(authed *gin.RouterGroup) { + g := authed.Group("/explore") + g.GET("/scales", middleware.RequireAdminPermission(h.Svc, admin.PermExploreRead), h.ListExploreScales) + g.GET("/scales/:id", middleware.RequireAdminPermission(h.Svc, admin.PermExploreRead), h.GetExploreScale) +} + +func (h *AdminHandler) ListExploreScales(c *gin.Context) { + items, err := h.Svc.ListScalesAdmin(c.Request.Context()) + if err != nil { + response.Fail(c, http.StatusInternalServerError, 50060, "list explore scales failed") + return + } + response.OK(c, gin.H{"items": items}) +} + +func (h *AdminHandler) GetExploreScale(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + response.Fail(c, http.StatusBadRequest, 40002, "invalid id") + return + } + row, err := h.Svc.GetScaleAdmin(c.Request.Context(), id) + if errors.Is(err, admin.ErrScaleNotFound) { + response.Fail(c, http.StatusNotFound, 40430, "scale not found") + return + } + if err != nil { + response.Fail(c, http.StatusInternalServerError, 50061, "get explore scale failed") + return + } + response.OK(c, row) +} diff --git a/apps/api/internal/integration/explore_scale_test.go b/apps/api/internal/integration/explore_scale_test.go new file mode 100644 index 0000000..ba34d64 --- /dev/null +++ b/apps/api/internal/integration/explore_scale_test.go @@ -0,0 +1,81 @@ +package integration_test + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "testing" + "time" + + "github.com/google/uuid" + "golang.org/x/crypto/bcrypt" +) + +func TestExploreScaleDefinitions(t *testing.T) { + r, pool := setupAPIPool(t) + ctx := context.Background() + tok := adminLogin(t, r, "admin", "change-me") + + _, code := doAdminJSON(t, r, http.MethodGet, "/api/v1/admin/explore/scales", nil, "") + if code != http.StatusUnauthorized { + t.Fatalf("expected 401, got %d", code) + } + + limitedRoleID := uuid.New() + _, err := pool.Exec(ctx, `INSERT INTO admin_roles(id, name, system) VALUES ($1,$2,false)`, + limitedRoleID, "sc_lim_"+limitedRoleID.String()[:8]) + if err != nil { + t.Fatal(err) + } + _, err = pool.Exec(ctx, `INSERT INTO admin_role_permissions(role_id, code) VALUES ($1,'admin.users.read')`, limitedRoleID) + if err != nil { + t.Fatal(err) + } + hash, err := bcrypt.GenerateFromPassword([]byte("limited-pass"), bcrypt.DefaultCost) + if err != nil { + t.Fatal(err) + } + limUser := fmt.Sprintf("sclim_%d", time.Now().UnixNano()) + _, err = pool.Exec(ctx, `INSERT INTO admin_accounts(username, password_hash, role_id) VALUES ($1,$2,$3)`, + limUser, string(hash), limitedRoleID) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { + _, _ = pool.Exec(ctx, `DELETE FROM admin_accounts WHERE username=$1`, limUser) + _, _ = pool.Exec(ctx, `DELETE FROM admin_roles WHERE id=$1`, limitedRoleID) + }) + limTok := adminLogin(t, r, limUser, "limited-pass") + _, code = doAdminJSON(t, r, http.MethodGet, "/api/v1/admin/explore/scales", nil, limTok) + if code != http.StatusForbidden { + t.Fatalf("expected 403, got %d", code) + } + + start := time.Now() + env, code := doAdminJSON(t, r, http.MethodGet, "/api/v1/admin/explore/scales", nil, tok) + if code != 200 || env.Code != 0 { + t.Fatalf("list http=%d msg=%s", code, env.Message) + } + if time.Since(start) > 500*time.Millisecond { + t.Fatalf("list too slow %v", time.Since(start)) + } + var list struct { + Items []struct { + ID string `json:"id"` + } `json:"items"` + } + _ = json.Unmarshal(env.Data, &list) + if len(list.Items) == 0 { + t.Fatal("expected at least one scale") + } + id := list.Items[0].ID + env, code = doAdminJSON(t, r, http.MethodGet, "/api/v1/admin/explore/scales/"+id, nil, tok) + if code != 200 { + t.Fatalf("get %d", code) + } + _, code = doAdminJSON(t, r, http.MethodGet, "/api/v1/admin/explore/scales/"+fakeUUID(), nil, tok) + if code != http.StatusNotFound { + t.Fatalf("expected 404, got %d", code) + } +} diff --git a/apps/api/internal/repository/scale_repo.go b/apps/api/internal/repository/scale_repo.go index 491f466..b73f38c 100644 --- a/apps/api/internal/repository/scale_repo.go +++ b/apps/api/internal/repository/scale_repo.go @@ -120,6 +120,19 @@ func (r *ScaleRepo) ListAllAdmin(ctx context.Context) ([]ScaleAdminItem, error) return out, rows.Err() } +// GetAdmin loads one scale by id for ops read. +func (r *ScaleRepo) GetAdmin(ctx context.Context, id uuid.UUID) (*ScaleAdminItem, error) { + var it ScaleAdminItem + err := r.Pool.QueryRow(ctx, ` + SELECT id, slug, title, description, status FROM scales + WHERE id=$1 AND deleted_at IS NULL`, id, + ).Scan(&it.ID, &it.Slug, &it.Title, &it.Description, &it.Status) + if err != nil { + return nil, err + } + return &it, nil +} + // UpdateStatus sets published|draft. func (r *ScaleRepo) UpdateStatus(ctx context.Context, id uuid.UUID, status string) error { return r.UpdateStatusWithAudit(ctx, id, status, uuid.Nil, nil) diff --git a/apps/api/internal/service/admin/content.go b/apps/api/internal/service/admin/content.go index 8da6e01..06245ea 100644 --- a/apps/api/internal/service/admin/content.go +++ b/apps/api/internal/service/admin/content.go @@ -42,6 +42,18 @@ func (s *Service) ListScalesAdmin(ctx context.Context) ([]repository.ScaleAdminI return s.Scales.ListAllAdmin(ctx) } +// GetScaleAdmin loads one scale for explore read projection. +func (s *Service) GetScaleAdmin(ctx context.Context, id uuid.UUID) (*repository.ScaleAdminItem, error) { + if s.Scales == nil { + return nil, errors.New("scales unavailable") + } + row, err := s.Scales.GetAdmin(ctx, id) + if errors.Is(err, pgx.ErrNoRows) { + return nil, ErrScaleNotFound + } + return row, err +} + // PatchScaleStatus updates published|draft and audits in one transaction. func (s *Service) PatchScaleStatus(ctx context.Context, adminID, scaleID uuid.UUID, status string) error { if status != "published" && status != "draft" { diff --git a/docs/BACKEND_DESIGN/BD-2026-040-scale-definition.md b/docs/BACKEND_DESIGN/BD-2026-040-scale-definition.md new file mode 100644 index 0000000..53e2897 --- /dev/null +++ b/docs/BACKEND_DESIGN/BD-2026-040-scale-definition.md @@ -0,0 +1,23 @@ +# Backend Design: ECR-040 ScaleDefinition + +| ID | BD-2026-040 | +| Status | Approved | +| Coding | Loop authorized | +| Level | L2 | +| Migration | NO | + +## Backend Change Boundary + +```text +Domain: ScaleDefinition (read projection of scales) +App: AdminHandler → admin.Service → ScaleRepo +API: GET /admin/explore/scales[+/:id] +Permission: admin.explore.read +UI: admin-h5 /catalogs +``` + +## Out of boundary + +PATCH status · 题干编辑 · UGC · Payment + +Rollback: remove routes/UI diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f28d3b9..e5824ad 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,7 @@ ## 2026-08-08 +- **ECR-040 Closed**:ExploreConfig ScaleDefinition(migration NO · admin-h5 /catalogs · 只读) - **ECR-039 Closed**:GrowthInsights FunnelDefinition(migration 000040 · admin client · /analytics/funnel-definitions · 只读) - **ECR-038 Closed**:GrowthInsights ReportTemplate(migration 000039 · admin client · /growth/report-templates · 只读) - **ECR-037 Closed**:ExploreConfig ImageCardDeck(migration 000038 · admin client · /explore/image-card-decks · 只读) diff --git a/docs/CODE_REVIEW/ECR-040.md b/docs/CODE_REVIEW/ECR-040.md new file mode 100644 index 0000000..77a34a8 --- /dev/null +++ b/docs/CODE_REVIEW/ECR-040.md @@ -0,0 +1,8 @@ +# CODE_REVIEW — ECR-040 + +**Verdict:** Approve → Closed + +Date: 2026-08-08 · Loop continuous + +- ScaleDefinition 只读;无 UGC/真支付 +- Integration AC mapped · OpenAPI updated diff --git a/docs/CONTRACT_DIFF/ECR-040.yaml b/docs/CONTRACT_DIFF/ECR-040.yaml new file mode 100644 index 0000000..a78dbe9 --- /dev/null +++ b/docs/CONTRACT_DIFF/ECR-040.yaml @@ -0,0 +1,23 @@ +ecr: ECR-040 +capability: ExploreConfig +bounded_context: Explore_Reports +parent: WAVE0-FROZEN +predecessor: ECR-039 +change: + type: additive +breaking_change: false +migration_required: false +compatibility_notes: > + Adds ScaleDefinition read projection over existing scales table. + Requires admin.explore.read. Does not add PATCH. + +apis: + - method: GET + path: /api/v1/admin/explore/scales + change: added + - method: GET + path: /api/v1/admin/explore/scales/{id} + change: added +perms: + - code: admin.explore.read + change: unchanged diff --git a/docs/ECR/ECR-040-scale-definition.md b/docs/ECR/ECR-040-scale-definition.md new file mode 100644 index 0000000..78ac2dc --- /dev/null +++ b/docs/ECR/ECR-040-scale-definition.md @@ -0,0 +1,15 @@ +# ECR-040 + +**Title:** ExploreConfig · ScaleDefinition(只读投影) +**Status:** **Closed** +**Closed:** 2026-08-08(Loop continuous) +**Parent:** WAVE0-FROZEN · **Predecessor:** ECR-039 Closed +**Change Level:** L2 + +## Change + +ScaleDefinition 只读 · migration NO · admin-h5 /catalogs + +## Linked + +Spec `ops-scale-definition.md` · BD-2026-040 · CONTRACT_DIFF/ECR-040.yaml · TEST_REPORT/ECR-040.md diff --git a/docs/ENGINEERING_SPEC/ECR-040-scale-definition.md b/docs/ENGINEERING_SPEC/ECR-040-scale-definition.md new file mode 100644 index 0000000..7e1a6a3 --- /dev/null +++ b/docs/ENGINEERING_SPEC/ECR-040-scale-definition.md @@ -0,0 +1,6 @@ +# ENGINEERING_SPEC — ECR-040 + +1. migration NO +2. AdminRepo/Service/Handler +3. OpenAPI + admin-h5 +4. Integration · Closed diff --git a/docs/HANDOFF/ECR-040-architect-to-engineer.md b/docs/HANDOFF/ECR-040-architect-to-engineer.md new file mode 100644 index 0000000..a689f3f --- /dev/null +++ b/docs/HANDOFF/ECR-040-architect-to-engineer.md @@ -0,0 +1,3 @@ +# HANDOFF — ECR-040 Architect → Engineer + +Loop continuous · Approved + Coding. Migration NO. Forbidden: UGC/真支付. diff --git a/docs/HANDOFF/ECR-040-engineer-to-reviewer.md b/docs/HANDOFF/ECR-040-engineer-to-reviewer.md new file mode 100644 index 0000000..128d903 --- /dev/null +++ b/docs/HANDOFF/ECR-040-engineer-to-reviewer.md @@ -0,0 +1,3 @@ +# HANDOFF — ECR-040 Engineer → Reviewer + +TestExploreScaleDefinitions PASS · Ready for Closed. diff --git a/docs/PRODUCT_SPEC/ECR-040-scale-definition.md b/docs/PRODUCT_SPEC/ECR-040-scale-definition.md new file mode 100644 index 0000000..34807d2 --- /dev/null +++ b/docs/PRODUCT_SPEC/ECR-040-scale-definition.md @@ -0,0 +1,3 @@ +# PRODUCT_SPEC — ECR-040 + +对齐 ops-scale-definition.md · Approved · Loop · L2 · ScaleDefinition 只读 diff --git a/docs/STATE/ECR-040.md b/docs/STATE/ECR-040.md new file mode 100644 index 0000000..9308f3b --- /dev/null +++ b/docs/STATE/ECR-040.md @@ -0,0 +1,6 @@ +# STATE — ECR-040 + +| Status | **Closed** | +| Phase | closed | +| Spec | ops-scale-definition.md | +| Updated | 2026-08-08 | diff --git a/docs/TASKS/TASK-040-ECR040.yaml b/docs/TASKS/TASK-040-ECR040.yaml new file mode 100644 index 0000000..94797b1 --- /dev/null +++ b/docs/TASKS/TASK-040-ECR040.yaml @@ -0,0 +1,12 @@ +id: TASK-040-ECR040 +ecr: ECR-040 +title: ExploreConfig · ScaleDefinition(只读投影) +role: engineer +status: closed +change_level: L2 +parent: WAVE0-FROZEN +predecessor: ECR-039 +acceptance: + - Spec AC mapped + - ScaleDefinition read only + - No UGC / payment diff --git a/docs/TEST_REPORT/ECR-040.md b/docs/TEST_REPORT/ECR-040.md new file mode 100644 index 0000000..532ccda --- /dev/null +++ b/docs/TEST_REPORT/ECR-040.md @@ -0,0 +1,33 @@ +# TEST_REPORT — ECR-040 ScaleDefinition + +Date: 2026-08-08 · Loop continuous · commit: `PENDING` + +## Commands + +```bash +cd apps/api && go test ./internal/integration/ -run TestExploreScaleDefinitions -count=1 +npm run build:admin +python3 scripts/ess-validate.py --phase review --ecr ECR-040 +python3 scripts/ess-gate-check.py --ecr ECR-040 +``` + +## Results + +| Check | Result | +|-------|--------| +| TestExploreScaleDefinitions | PASS | +| build:admin | PASS | +| ess-validate review | PASS | +| ess-gate-check | PASS | + +## AC + +| ID | Evidence | +|----|----------| +| AC-F-01 | list seed/empty ok | +| AC-F-02 | get 200 | +| AC-F-03 | 未知 id → 404 | +| AC-S-01 | 401 | +| AC-S-02 | 403 | +| AC-P-01 | list < 500ms | +| AC-O-01 | N/A 只读 | diff --git a/docs/TRACEABILITY.md b/docs/TRACEABILITY.md index cff2f40..a8d857a 100644 --- a/docs/TRACEABILITY.md +++ b/docs/TRACEABILITY.md @@ -44,3 +44,4 @@ | ECR-037 | ExploreConfig · ImageCardDeck | **Closed** | Spec ops-image-card-deck.md · BD-2026-037 · migration 000038 · TEST_REPORT · CODE_REVIEW · Loop continuous | | ECR-038 | GrowthInsights · ReportTemplate | **Closed** | Spec ops-report-template.md · BD-2026-038 · migration 000039 · TEST_REPORT · CODE_REVIEW · Loop continuous | | ECR-039 | GrowthInsights · FunnelDefinition | **Closed** | Spec ops-funnel-definition.md · BD-2026-039 · migration 000040 · TEST_REPORT · CODE_REVIEW · Loop continuous | +| ECR-040 | ExploreConfig · ScaleDefinition | **Closed** | Spec ops-scale-definition.md · BD-2026-040 · migration NO · TEST_REPORT · CODE_REVIEW · Loop continuous | diff --git a/docs/WAVE0/LOOP_AUTHORIZATION.md b/docs/WAVE0/LOOP_AUTHORIZATION.md index e067c55..645169e 100644 --- a/docs/WAVE0/LOOP_AUTHORIZATION.md +++ b/docs/WAVE0/LOOP_AUTHORIZATION.md @@ -55,4 +55,4 @@ Human 明文:**直接用 Loop,不用人工确认。** | Done | Next | |------|------| -| ECR-013A…039 Closed | **ECR-040** ScaleDefinition 只读投影 | +| ECR-013A…040 Closed | **STOP** — 队列完成;禁真支付/UGC/soft-delete | diff --git a/proto/openapi.yaml b/proto/openapi.yaml index 165d3d8..49c92e3 100644 --- a/proto/openapi.yaml +++ b/proto/openapi.yaml @@ -891,6 +891,34 @@ paths: '404': description: Not found + /api/v1/admin/explore/scales: + get: + tags: [admin] + summary: List ScaleDefinition read projection + description: Requires admin.explore.read · reuses scales table + responses: + '200': + description: OK + '401': + description: Unauthorized + '403': + description: Forbidden + + /api/v1/admin/explore/scales/{id}: + get: + tags: [admin] + summary: Get ScaleDefinition + parameters: + - in: path + name: id + required: true + schema: { type: string, format: uuid } + responses: + '200': + description: OK + '404': + description: Not found + /api/v1/admin/explore/star-configs: get: tags: [admin]