+ Setting
This commit is contained in:
parent
de3fb44d27
commit
95bbe5f7ea
4 changed files with 66 additions and 13 deletions
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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{}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 绑定数据模型
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue