+ Delete
This commit is contained in:
parent
45c061dccb
commit
de3fb44d27
2 changed files with 51 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/kun/any"
|
"github.com/yaoapp/kun/any"
|
||||||
"github.com/yaoapp/xiang/table"
|
"github.com/yaoapp/xiang/table"
|
||||||
|
"github.com/yaoapp/xun/capsule"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestProcessPing(t *testing.T) {
|
func TestProcessPing(t *testing.T) {
|
||||||
|
|
@ -72,4 +73,38 @@ func TestProcessSave(t *testing.T) {
|
||||||
response := table.ProcessSave(process)
|
response := table.ProcessSave(process)
|
||||||
assert.NotNil(t, response)
|
assert.NotNil(t, response)
|
||||||
assert.True(t, any.Of(response).IsInt())
|
assert.True(t, any.Of(response).IsInt())
|
||||||
|
|
||||||
|
id := any.Of(response).CInt()
|
||||||
|
|
||||||
|
// 清空数据
|
||||||
|
capsule.Query().Table("service").Where("id", id).Delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessDelete(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 := table.ProcessSave(process)
|
||||||
|
assert.NotNil(t, response)
|
||||||
|
assert.True(t, any.Of(response).IsInt())
|
||||||
|
|
||||||
|
id := any.Of(response).CInt()
|
||||||
|
args = []interface{}{
|
||||||
|
"service",
|
||||||
|
id,
|
||||||
|
}
|
||||||
|
process = gou.NewProcess("xiang.table.Delete", args...)
|
||||||
|
response = table.ProcessDelete(process)
|
||||||
|
assert.Nil(t, response)
|
||||||
|
|
||||||
|
// 清空数据
|
||||||
|
capsule.Query().Table("service").Where("id", id).Delete()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ func init() {
|
||||||
gou.RegisterProcessHandler("xiang.table.Search", ProcessSearch)
|
gou.RegisterProcessHandler("xiang.table.Search", ProcessSearch)
|
||||||
gou.RegisterProcessHandler("xiang.table.Find", ProcessFind)
|
gou.RegisterProcessHandler("xiang.table.Find", ProcessFind)
|
||||||
gou.RegisterProcessHandler("xiang.table.Save", ProcessSave)
|
gou.RegisterProcessHandler("xiang.table.Save", ProcessSave)
|
||||||
|
gou.RegisterProcessHandler("xiang.table.Delete", ProcessDelete)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessSearch xiang.table.Search
|
// ProcessSearch xiang.table.Search
|
||||||
|
|
@ -60,3 +61,18 @@ func ProcessSave(process *gou.Process) interface{} {
|
||||||
}
|
}
|
||||||
return gou.NewProcess(api.Process, process.Args[1]).Run()
|
return gou.NewProcess(api.Process, process.Args[1]).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessDelete xiang.table.Delete
|
||||||
|
// 删除指定主键值的数据记录, 请求成功返回null
|
||||||
|
func ProcessDelete(process *gou.Process) interface{} {
|
||||||
|
process.ValidateArgNums(2)
|
||||||
|
name := process.ArgsString(0)
|
||||||
|
table := Select(name)
|
||||||
|
api := table.APIs["delete"].ValidateLoop("xiang.table.delete")
|
||||||
|
if process.NumOfArgsIs(3) && api.IsAllow(process.Args[2]) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
id := process.Args[1]
|
||||||
|
return gou.NewProcess(api.Process, id).Run()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue