+ Table Select API
This commit is contained in:
parent
4f82bfff3e
commit
0e44d5689f
6 changed files with 66 additions and 5 deletions
|
|
@ -44,7 +44,7 @@ func apiFindDefault(model *gou.Model, withs map[string]gou.With) share.API {
|
|||
}
|
||||
}
|
||||
|
||||
// apiFindDefault 接口默认值
|
||||
// apiDefault 接口默认值
|
||||
func apiDefault(model *gou.Model, name string, process string) share.API {
|
||||
return share.API{
|
||||
Name: name,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ func init() {
|
|||
// 注册处理器
|
||||
gou.RegisterProcessHandler("xiang.table.Search", ProcessSearch)
|
||||
gou.RegisterProcessHandler("xiang.table.Find", ProcessFind)
|
||||
gou.RegisterProcessHandler("xiang.table.Select", ProcessSelect)
|
||||
gou.RegisterProcessHandler("xiang.table.Save", ProcessSave)
|
||||
gou.RegisterProcessHandler("xiang.table.Delete", ProcessDelete)
|
||||
gou.RegisterProcessHandler("xiang.table.Insert", ProcessInsert)
|
||||
|
|
@ -268,3 +269,16 @@ func ProcessQuickSave(process *gou.Process) interface{} {
|
|||
|
||||
return gou.NewProcess(api.Process, args...).Run()
|
||||
}
|
||||
|
||||
// ProcessSelect xiang.table.Select
|
||||
// 单表数据查询,一般用于下拉菜单检索
|
||||
func ProcessSelect(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
name := process.ArgsString(0)
|
||||
table := Select(name)
|
||||
api := table.APIs["select"].ValidateLoop("xiang.table.select")
|
||||
if process.NumOfArgsIs(5) && api.IsAllow(process.Args[4]) {
|
||||
return nil
|
||||
}
|
||||
return gou.NewProcess(api.Process, process.Args[1:]...).Run()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
"github.com/yaoapp/xiang/config"
|
||||
"github.com/yaoapp/xiang/model"
|
||||
"github.com/yaoapp/xiang/share"
|
||||
|
|
@ -358,3 +359,33 @@ func TestTableProcessQuickSave(t *testing.T) {
|
|||
// 清空数据
|
||||
capsule.Query().Table("service").WhereIn("id", []int{id, newID[0]}).Delete()
|
||||
}
|
||||
|
||||
func TestTableProcessSelect(t *testing.T) {
|
||||
args := []interface{}{
|
||||
"service",
|
||||
map[string]interface{}{
|
||||
"name": "腾讯黑岩云主机",
|
||||
"short_name": "高性能云主机",
|
||||
"kind_id": 3,
|
||||
"manu_id": 1,
|
||||
"price_options": []string{"按月订阅"},
|
||||
},
|
||||
}
|
||||
process := gou.NewProcess("xiang.table.Save", args...)
|
||||
response := ProcessSave(process)
|
||||
assert.NotNil(t, response)
|
||||
assert.True(t, any.Of(response).IsInt())
|
||||
|
||||
id := any.Of(response).CInt()
|
||||
|
||||
args = []interface{}{"service", "腾讯", "name", "id"}
|
||||
|
||||
data := gou.NewProcess("xiang.table.select", args...).Run().([]maps.MapStrAny)
|
||||
assert.Greater(t, len(data), 1)
|
||||
for _, row := range data {
|
||||
assert.Contains(t, row.Get("name"), "腾讯")
|
||||
}
|
||||
|
||||
// 清空数据
|
||||
capsule.Query().Table("service").WhereIn("id", []int{id}).Delete()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,8 @@ func getDefaultAPIs(bind Bind) map[string]share.API {
|
|||
"delete-where": apiDefaultWhere(model, bind.Withs, "delete-where", "DeleteWhere"),
|
||||
"update-in": apiDefault(model, "update-in", "UpdateWhere"),
|
||||
"update-where": apiDefaultWhere(model, bind.Withs, "update-where", "UpdateWhere"),
|
||||
"quicksave": apiDefault(model, "quicksave", "EachSaveAfterDelete"),
|
||||
"quicksave": apiDefault(model, "quicksave", "EachSaveAfterDelete"), // 批量保存
|
||||
"select": apiDefault(model, "select", "SelectOption"), // 选择
|
||||
}
|
||||
|
||||
return apis
|
||||
|
|
|
|||
|
|
@ -18,9 +18,8 @@
|
|||
}
|
||||
},
|
||||
"apis": {
|
||||
"save": {
|
||||
"guard": "-"
|
||||
},
|
||||
"save": { "guard": "-" },
|
||||
"select": { "guard": "-" },
|
||||
"search": {
|
||||
"process": "models.service.Paginate",
|
||||
"guard": "-",
|
||||
|
|
|
|||
|
|
@ -25,6 +25,22 @@
|
|||
"type": "application/json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/:name/select",
|
||||
"method": "GET",
|
||||
"process": "xiang.table.Select",
|
||||
"in": [
|
||||
"$param.name",
|
||||
"$query.keyword",
|
||||
"$query.name",
|
||||
"$query.value",
|
||||
"$query.limit"
|
||||
],
|
||||
"out": {
|
||||
"status": 200,
|
||||
"type": "application/json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/:name/save",
|
||||
"method": "POST",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue