From 8bd280bb6b639569225c34a28659adcf13cdae75 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 14 Apr 2022 07:47:20 +0800 Subject: [PATCH] [Add] xiang.table.Find query DSL support --- api/api_test.go | 2 +- flow/flow_test.go | 2 +- table/process.go | 6 +++- tests/apis/demo.http.json | 39 ++++++++++++++++++++ tests/flows/demo/admin.flow.json | 61 ++++++++++++++++++++++++++++++++ tests/flows/demo/token.flow.json | 13 +++++++ 6 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 tests/apis/demo.http.json create mode 100644 tests/flows/demo/admin.flow.json create mode 100644 tests/flows/demo/token.flow.json diff --git a/api/api_test.go b/api/api_test.go index 79f8cf18..8660f461 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -27,6 +27,6 @@ func check(t *testing.T) { wskeys = append(wskeys, key) } - assert.Equal(t, 4, len(keys)) + assert.Equal(t, 5, len(keys)) assert.Equal(t, 1, len(wskeys)) } diff --git a/flow/flow_test.go b/flow/flow_test.go index 394da9b4..b1b06c19 100644 --- a/flow/flow_test.go +++ b/flow/flow_test.go @@ -20,5 +20,5 @@ func check(t *testing.T) { for key := range gou.Flows { keys = append(keys, key) } - assert.Equal(t, 24, len(keys)) + assert.Equal(t, 26, len(keys)) } diff --git a/table/process.go b/table/process.go index f46ec486..063f9860 100644 --- a/table/process.go +++ b/table/process.go @@ -75,7 +75,11 @@ func ProcessFind(process *gou.Process) interface{} { // 参数表 process.ValidateArgNums(2) id := process.Args[1] - param := api.MergeDefaultQueryParam(gou.QueryParam{}, 2, process.Sid) + queryParam := gou.QueryParam{} + if process.NumOfArgs() == 3 { + queryParam = process.ArgsQueryParams(2) + } + param := api.MergeDefaultQueryParam(queryParam, 1, process.Sid) // 查询数据 response := gou.NewProcess(api.Process, id, param). diff --git a/tests/apis/demo.http.json b/tests/apis/demo.http.json new file mode 100644 index 00000000..b04f3239 --- /dev/null +++ b/tests/apis/demo.http.json @@ -0,0 +1,39 @@ +{ + "name": "Demo", + "version": "1.0.0", + "description": "demo", + "group": "demo", + "guard": "-", + "paths": [ + { + "path": "/user", + "method": "GET", + "process": "flows.demo.user", + "in": ["$query.id"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/admin", + "method": "GET", + "process": "flows.demo.admin", + "in": ["$query.id"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/token", + "method": "GET", + "process": "flows.demo.token", + "in": ["$query.id"], + "out": { + "status": 200, + "type": "application/json" + } + } + ] +} diff --git a/tests/flows/demo/admin.flow.json b/tests/flows/demo/admin.flow.json new file mode 100644 index 00000000..9fb64aa6 --- /dev/null +++ b/tests/flows/demo/admin.flow.json @@ -0,0 +1,61 @@ +{ + "label": "Auto Login", + "version": "1.0.0", + "description": "Auto Login for demo", + "nodes": [ + { + "name": "User", + "process": "models.xiang.user.Get", + "args": [ + { + "select": ["id", "email", "name", "type"], + "wheres": [{ "column": "id", "value": 1 }], + "limit": 1 + } + ] + }, + { + "name": "Menu", + "process": "flows.xiang.menu", + "args": ["{{$res.User.0.id}}"] + }, + { + "name": "SID", + "process": "session.start" + }, + { + "name": "JWT", + "process": "xiang.helper.JWTMake", + "args": [ + "{{$res.User.0.id}}", + {}, + { + "timeout": 3600, + "sid": "{{$res.SID}}" + } + ] + }, + { + "name": "Set User", + "process": "session.set", + "args": ["user", "{{$res.User.0}}"] + }, + { + "name": "Set issuer", + "process": "session.set", + "args": ["issuer", "xiang"] + }, + { + "name": "Set User ID", + "process": "session.set", + "args": ["user_id", "{{$res.User.0.id}}"] + } + ], + "output": { + "sid": "{{$res.SID}}", + "user": "{{$res.User.0}}", + "menus": "{{$res.Menu}}", + "token": "{{$res.JWT.token}}", + "expires_at": "{{$res.JWT.expires_at}}" + } +} diff --git a/tests/flows/demo/token.flow.json b/tests/flows/demo/token.flow.json new file mode 100644 index 00000000..ca9002b2 --- /dev/null +++ b/tests/flows/demo/token.flow.json @@ -0,0 +1,13 @@ +{ + "label": "Auto Login", + "version": "1.0.0", + "description": "Auto Login for demo", + "nodes": [ + { + "name": "User", + "process": "flows.demo.admin", + "args": [] + } + ], + "output": "{{$res.User.token}}" +}