diff --git a/global/process_test.go b/global/process_test.go index 8e0b67c1..0bb3b8e3 100644 --- a/global/process_test.go +++ b/global/process_test.go @@ -108,3 +108,20 @@ func TestProcessDelete(t *testing.T) { // 清空数据 capsule.Query().Table("service").Where("id", id).Delete() } + +func TestProcessSetting(t *testing.T) { + args := []interface{}{"service"} + process := gou.NewProcess("xiang.table.Setting", args...) + response := table.ProcessSetting(process) + assert.NotNil(t, response) + res := any.Of(response).Map() + assert.Equal(t, res.Get("name"), "云服务库") + assert.True(t, res.Has("title")) + assert.True(t, res.Has("decription")) + assert.True(t, res.Has("columns")) + assert.True(t, res.Has("filters")) + assert.True(t, res.Has("list")) + assert.True(t, res.Has("edit")) + assert.True(t, res.Has("view")) + assert.True(t, res.Has("insert")) +} diff --git a/table/api.go b/table/api.go index a830102c..5f038b2a 100644 --- a/table/api.go +++ b/table/api.go @@ -129,7 +129,7 @@ func apiDefaultSetting(table *Table) API { return API{ Name: "setting", Guard: "bearer-jwt", - Process: fmt.Sprintf("tables.%s.Setting", table.Table), + Process: fmt.Sprintf("xiang.table.setting"), } } @@ -161,6 +161,11 @@ func (api API) ValidateLoop(name string) API { return api } +// ProcessIs 检查处理器名称 +func (api API) ProcessIs(name string) bool { + return strings.ToLower(api.Process) == strings.ToLower(name) +} + // DefaultQueryParams 读取参数 QueryParam func (api API) DefaultQueryParams(i int, defaults ...gou.QueryParam) gou.QueryParam { param := gou.QueryParam{} diff --git a/table/process.go b/table/process.go index 4d6a8312..7b956159 100644 --- a/table/process.go +++ b/table/process.go @@ -2,6 +2,7 @@ package table import ( "github.com/yaoapp/gou" + "github.com/yaoapp/kun/maps" ) func init() { @@ -10,6 +11,7 @@ func init() { gou.RegisterProcessHandler("xiang.table.Find", ProcessFind) gou.RegisterProcessHandler("xiang.table.Save", ProcessSave) gou.RegisterProcessHandler("xiang.table.Delete", ProcessDelete) + gou.RegisterProcessHandler("xiang.table.Setting", ProcessSetting) } // ProcessSearch xiang.table.Search @@ -76,3 +78,30 @@ func ProcessDelete(process *gou.Process) interface{} { id := process.Args[1] return gou.NewProcess(api.Process, id).Run() } + +// ProcessSetting xiang.table.Setting +// 删除指定主键值的数据记录, 请求成功返回null +func ProcessSetting(process *gou.Process) interface{} { + process.ValidateArgNums(1) + name := process.ArgsString(0) + table := Select(name) + api := table.APIs["setting"] + if process.NumOfArgsIs(2) && api.IsAllow(process.Args[1]) { + return nil + } + if api.ProcessIs("xiang.table.Setting") { + return maps.Map{ + "name": table.Name, + "title": table.Title, + "decription": table.Decription, + "columns": table.Columns, + "filters": table.Filters, + "list": table.List, + "edit": table.Edit, + "view": table.View, + "insert": table.Insert, + } + } + + return gou.NewProcess(api.Process).Run() +} diff --git a/table/types.go b/table/types.go index f099b5ee..d96bbfb7 100644 --- a/table/types.go +++ b/table/types.go @@ -4,18 +4,20 @@ import "github.com/yaoapp/gou" // Table 数据表格配置结构 type Table struct { - Table string `json:"-"` - Source string `json:"-"` - Name string `json:"name"` - Version string `json:"version"` - Bind Bind `json:"bind,omitempty"` - APIs map[string]API `json:"apis,omitempty"` - Columns map[string]Column `json:"columns,omitempty"` - Filters map[string]Filter `json:"filters,omitempty"` - List Page `json:"list,omitempty"` - Edit Page `json:"edit,omitempty"` - View Page `json:"view,omitempty"` - Insert Page `json:"insert,omitempty"` + Table string `json:"-"` + Source string `json:"-"` + Name string `json:"name"` + Version string `json:"version"` + Title string `json:"title,omitempty"` + Decription string `json:"decription,omitempty"` + Bind Bind `json:"bind,omitempty"` + APIs map[string]API `json:"apis,omitempty"` + Columns map[string]Column `json:"columns,omitempty"` + Filters map[string]Filter `json:"filters,omitempty"` + List Page `json:"list,omitempty"` + Edit Page `json:"edit,omitempty"` + View Page `json:"view,omitempty"` + Insert Page `json:"insert,omitempty"` } // Bind 绑定数据模型