@@ -6,11 +6,9 @@ import (
66 "strings"
77
88 "github.com/glennliao/apijson-go/config"
9- "github.com/glennliao/apijson-go/config/executor"
109 "github.com/glennliao/apijson-go/consts"
1110 "github.com/glennliao/apijson-go/model"
1211 "github.com/glennliao/apijson-go/util"
13- "github.com/gogf/gf/v2/errors/gerror"
1412 "github.com/samber/lo"
1513)
1614
@@ -45,7 +43,6 @@ func newNode(key string, req []model.Map, structure *config.Structure, executor
4543 n .Data = []model.Map {}
4644 n .Where = []model.Map {}
4745
48- // ?
4946 for _ = range n .req {
5047
5148 n .Data = append (n .Data , model.Map {})
@@ -54,7 +51,7 @@ func newNode(key string, req []model.Map, structure *config.Structure, executor
5451 }
5552
5653 if strings .HasSuffix (key , consts .ListKeySuffix ) {
57- n .Key = key [ 0 : len (key ) - len ( consts .ListKeySuffix )]
54+ n .Key = util . RemoveSuffix (key , consts .ListKeySuffix )
5855 n .IsList = true
5956 }
6057
@@ -65,10 +62,6 @@ func newNode(key string, req []model.Map, structure *config.Structure, executor
6562func (n * Node ) parseReq (method string ) {
6663
6764 for i , item := range n .req {
68-
69- // n.Data = append(n.Data, model.Map{})
70- // n.Where = append(n.Where, model.Map{})
71-
7265 for key , val := range item {
7366
7467 if key == consts .Role {
@@ -84,7 +77,7 @@ func (n *Node) parseReq(method string) {
8477 case http .MethodDelete :
8578 n.Where [i ][key ] = val
8679 case http .MethodPut :
87- if key == n .RowKey || key == n .RowKey + "{}" {
80+ if key == n .RowKey || key == n .RowKey + consts . OpIn {
8881 n.Where [i ][key ] = val
8982 } else {
9083 n.Data [i ][key ] = val
@@ -100,7 +93,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
10093
10194 key := n .Key
10295 if strings .HasSuffix (key , consts .ListKeySuffix ) {
103- key = key [ 0 : len (key ) - 2 ]
96+ key = util . RemoveSuffix (key , consts . ListKeySuffix )
10497 }
10598 access , err := n .Action .ActionConfig .GetAccessConfig (key , true )
10699
@@ -179,13 +172,13 @@ func (n *Node) checkAccess(ctx context.Context, method string, accessRoles []str
179172 }
180173
181174 if role == consts .DENY {
182- return gerror . Newf ( "deny node: %s with %s" , n .Key , n .Role )
175+ return consts . NewDenyErr ( n .Key , n .Role )
183176 }
184177
185178 n .Role = role
186179
187180 if ! lo .Contains (accessRoles , role ) {
188- return gerror . Newf ( "node not access: %s with %s" , n .Key , n .Role )
181+ return consts . NewNoAccessErr ( n .Key , n .Role )
189182 }
190183
191184 return nil
@@ -231,26 +224,26 @@ func (n *Node) checkReq() error {
231224 // must
232225 for _ , key := range n .structure .Must {
233226 if _ , exists := item [key ]; ! exists {
234- return gerror . New ( "structure错误: 400, 缺少" + n .Key + "." + key )
227+ return consts . NewStructureKeyNoFoundErr ( n .Key + "." + key )
235228 }
236229 }
237230
238231 // refuse
239232 if len (n .structure .Refuse ) > 0 && n .structure .Refuse [0 ] == "!" {
240233 if len (n .structure .Must ) == 0 {
241- return gerror . New ( "structure错误: 400, REFUSE为!时必须指定MUST" + n .Key )
234+ return consts . NewValidStructureErr ( " REFUSE为!时必须指定MUST: " + n .Key )
242235 }
243236
244237 for key , _ := range item {
245238 if ! lo .Contains (n .structure .Must , key ) {
246- return gerror . New ( "structure错误: 400, 不能包含" + n .Key + "." + key )
239+ return consts . NewValidStructureErr ( " 不能包含: " + n .Key + "." + key )
247240 }
248241 }
249242
250243 } else {
251244 for _ , key := range n .structure .Refuse {
252245 if _ , exists := item [key ]; exists {
253- return gerror . New ( "structure错误: 400, 不能包含" + n .Key + "." + key )
246+ return consts . NewValidStructureErr ( " 不能包含: " + n .Key + "." + key )
254247 }
255248 }
256249 }
@@ -375,16 +368,22 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
375368 case http .MethodDelete :
376369
377370 default :
378- return nil , gerror .New ("undefined method:" + method )
371+ return nil , consts .NewMethodNotSupportErr (method )
372+ }
373+
374+ executor , err := GetActionExecutor (n .executor )
375+ if err != nil {
376+ return nil , err
379377 }
380378
381- ret , err = executor .GetActionExecutor (n .executor ).Do (ctx , executor.ActionExecutorReq {
382- Method : method ,
383- Table : n .tableName ,
384- Data : n .Data ,
385- Where : n .Where ,
386- Access : access ,
387- Config : n .Action .ActionConfig ,
379+ ret , err = executor .Do (ctx , ActionExecutorReq {
380+ Method : method ,
381+ Table : n .tableName ,
382+ Data : n .Data ,
383+ Where : n .Where ,
384+ Access : access ,
385+ Config : n .Action .ActionConfig ,
386+ NewQuery : n .Action .NewQuery ,
388387 })
389388
390389 if err != nil {
0 commit comments