From 4ebf0afc2207d03efb9a836eed0d0e2dbf7d3e18 Mon Sep 17 00:00:00 2001 From: lianjianwei2024 <168657369+lianjianwei2024@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:26:43 +0800 Subject: [PATCH] feat: new suffix group auto-creates one workspace row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新建分组即自动带一行工作行(双击命名、上传模板/向下插入行/↑/↓/×按钮齐全), 消灭空分组死步骤;集成测试清理只清自建数据的口径下断言按行名定位 --- backend/internal/httpapi/suffixes.go | 22 +++++++++++++++++++--- backend/internal/httpapi/suffixes_test.go | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/backend/internal/httpapi/suffixes.go b/backend/internal/httpapi/suffixes.go index 5150ef5..e76c17d 100644 --- a/backend/internal/httpapi/suffixes.go +++ b/backend/internal/httpapi/suffixes.go @@ -608,14 +608,30 @@ func (a *BusinessAPI) createSuffixGroup(c *gin.Context) { } var order sql.NullInt64 _ = a.db.QueryRowContext(c, "SELECT MAX(sort_order) FROM suffix_groups").Scan(&order) - res, err := a.db.ExecContext(c, + tx, err := a.db.BeginTx(c, nil) + if err != nil { + apiError(c, 500, "internal_error", "分组创建失败") + return + } + defer tx.Rollback() + gres, err := tx.ExecContext(c, "INSERT INTO suffix_groups(name,sort_order) VALUES(?,?)", name, order.Int64+1) if err != nil { apiError(c, 500, "internal_error", "分组创建失败") return } - id, _ := res.LastInsertId() - c.JSON(201, gin.H{"data": gin.H{"id": id, "name": name, "suffixes": []suffixOverview{}}}) + gid, _ := gres.LastInsertId() + // 新建分组自动带一行工作行,按钮齐全,双击即可命名。 + if _, err := tx.ExecContext(c, + "INSERT INTO suffixes(group_id,name,sort_order) VALUES(?,'',0)", gid); err != nil { + apiError(c, 500, "internal_error", "分组创建失败") + return + } + if err := tx.Commit(); err != nil { + apiError(c, 500, "internal_error", "分组创建失败") + return + } + c.JSON(201, gin.H{"data": gin.H{"id": gid, "name": name, "suffixes": []suffixOverview{}}}) } func (a *BusinessAPI) renameSuffixGroup(c *gin.Context) { diff --git a/backend/internal/httpapi/suffixes_test.go b/backend/internal/httpapi/suffixes_test.go index 1c2e6de..0cbe2e4 100644 --- a/backend/internal/httpapi/suffixes_test.go +++ b/backend/internal/httpapi/suffixes_test.go @@ -223,7 +223,16 @@ func TestSuffixAdminIntegration(t *testing.T) { } w = authed(http.MethodGet, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/page", dirID), "") sfx := getJSON(w)["data"].(map[string]any)["suffixes"].([]any) - if !sfx[0].(map[string]any)["anchor"].(bool) { + cos4 := func() map[string]any { + for _, line := range sfx { + if line.(map[string]any)["name"] == "cos4" { + return line.(map[string]any) + } + } + t.Fatal("找不到 cos4 行") + return nil + }() + if !cos4["anchor"].(bool) { t.Fatal("锚定后 anchor 应为 true") } @@ -251,7 +260,14 @@ func TestSuffixAdminIntegration(t *testing.T) { } w = authed(http.MethodGet, "/api/v1/suffix-admin/overview", "") groups := getJSON(w)["data"].(map[string]any)["groups"].([]any) - files := groups[0].(map[string]any)["suffixes"].([]any)[0].(map[string]any)["files"].([]any) + var files []any + for _, line := range groups[0].(map[string]any)["suffixes"].([]any) { + m := line.(map[string]any) + if m["name"] == "cos4" { + files = m["files"].([]any) + break + } + } if len(files) != 1 { t.Fatalf("概览文件数=%d, want 1", len(files)) }