feat: new suffix group auto-creates one workspace row
新建分组即自动带一行工作行(双击命名、上传模板/向下插入行/↑/↓/×按钮齐全), 消灭空分组死步骤;集成测试清理只清自建数据的口径下断言按行名定位
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user