Skip to content

Commit

Permalink
+ Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Sep 29, 2021
1 parent de3fb44 commit 95bbe5f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
17 changes: 17 additions & 0 deletions global/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
7 changes: 6 additions & 1 deletion table/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}

Expand Down Expand Up @@ -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{}
Expand Down
29 changes: 29 additions & 0 deletions table/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package table

import (
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/maps"
)

func init() {
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
26 changes: 14 additions & 12 deletions table/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 绑定数据模型
Expand Down

0 comments on commit 95bbe5f

Please sign in to comment.