|
|
@@ -77,14 +77,26 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
|
|
|
|
|
|
copyBuilder := builder.Url(http.MethodPost, domainPath+"/create")
|
|
|
|
|
|
- if createOptions.beforeBuilderCallback != nil {
|
|
|
- copyBuilder = createOptions.beforeBuilderCallback(copyBuilder)
|
|
|
- }
|
|
|
+ postRequest := gateway.NewPostRequest(params.ServiceVersionedUrl+domainPath+"/create",
|
|
|
+ gateway.PostRequestWithBodyForm(func(c *api.Context, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (any, error) {
|
|
|
+ _, err := gateway.FormJsonBodyWithTenantIDAndUserIDFunc("tenantId", "createUserId")(c, historyRequest, resultMap)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if createOptions.beforeBuilderCallback != nil {
|
|
|
+ copyBuilder = createOptions.beforeBuilderCallback(copyBuilder, c)
|
|
|
+ }
|
|
|
+
|
|
|
+ jsonBody, err := c.GetJsonBody()
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return jsonBody.Map(), nil
|
|
|
+ }))
|
|
|
|
|
|
- copyBuilder = copyBuilder.Post(gateway.NewPostRequest(params.ServiceVersionedUrl+domainPath+"/create",
|
|
|
- gateway.PostRequestWithBodyForm(
|
|
|
- gateway.FormJsonBodyWithTenantIDAndUserIDFunc("tenantId", "createUserId"))),
|
|
|
- createOptions.requestResponseCallback)
|
|
|
+ copyBuilder = copyBuilder.Post(postRequest, createOptions.requestResponseCallback)
|
|
|
|
|
|
if createOptions.afterBuilderCallback != nil {
|
|
|
copyBuilder = createOptions.afterBuilderCallback(copyBuilder)
|
|
|
@@ -99,12 +111,16 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
|
|
|
|
|
|
copyBuilder := builder.Url(http.MethodDelete, domainPath+"/delete")
|
|
|
|
|
|
- if deleteOptions.beforeBuilderCallback != nil {
|
|
|
- copyBuilder = deleteOptions.beforeBuilderCallback(copyBuilder)
|
|
|
- }
|
|
|
+ deleteRequest := gateway.NewDeleteRequest(params.ServiceVersionedUrl+domainPath+"/delete",
|
|
|
+ gateway.DeleteRequestWithQueryParamsForm(func(c *api.Context, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (map[string]string, error) {
|
|
|
+ if deleteOptions.beforeBuilderCallback != nil {
|
|
|
+ copyBuilder = deleteOptions.beforeBuilderCallback(copyBuilder, c)
|
|
|
+ }
|
|
|
+
|
|
|
+ return c.GetQueryParams().Map(), nil
|
|
|
+ }))
|
|
|
|
|
|
- copyBuilder = copyBuilder.Delete(gateway.NewDeleteRequest(params.ServiceVersionedUrl+domainPath+"/delete"),
|
|
|
- deleteOptions.requestResponseCallback)
|
|
|
+ copyBuilder = copyBuilder.Delete(deleteRequest, deleteOptions.requestResponseCallback)
|
|
|
|
|
|
if deleteOptions.afterBuilderCallback != nil {
|
|
|
copyBuilder = deleteOptions.afterBuilderCallback(copyBuilder)
|
|
|
@@ -119,14 +135,26 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
|
|
|
|
|
|
copyBuilder := builder.Url(http.MethodPut, domainPath+"/update")
|
|
|
|
|
|
- if updateOptions.beforeBuilderCallback != nil {
|
|
|
- copyBuilder = updateOptions.beforeBuilderCallback(copyBuilder)
|
|
|
- }
|
|
|
+ putRequest := gateway.NewPutRequest(params.ServiceVersionedUrl+domainPath+"/update",
|
|
|
+ gateway.PutRequestWithBodyForm(func(c *api.Context, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (any, error) {
|
|
|
+ _, err := gateway.FormJsonBodyWithTenantIDAndUserIDFunc("", "updateUserId")(c, historyRequest, resultMap)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if updateOptions.beforeBuilderCallback != nil {
|
|
|
+ copyBuilder = updateOptions.beforeBuilderCallback(copyBuilder, c)
|
|
|
+ }
|
|
|
|
|
|
- copyBuilder = copyBuilder.Put(gateway.NewPutRequest(params.ServiceVersionedUrl+domainPath+"/update",
|
|
|
- gateway.PutRequestWithBodyForm(
|
|
|
- gateway.FormJsonBodyWithTenantIDAndUserIDFunc("", "updateUserId"))),
|
|
|
- updateOptions.requestResponseCallback)
|
|
|
+ jsonBody, err := c.GetJsonBody()
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return jsonBody.Map(), nil
|
|
|
+ }))
|
|
|
+
|
|
|
+ copyBuilder = copyBuilder.Put(putRequest, updateOptions.requestResponseCallback)
|
|
|
|
|
|
if updateOptions.afterBuilderCallback != nil {
|
|
|
copyBuilder = updateOptions.afterBuilderCallback(copyBuilder)
|
|
|
@@ -141,13 +169,21 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
|
|
|
|
|
|
copyBuilder := builder.Url(http.MethodGet, domainPath+"/query")
|
|
|
|
|
|
- if queryOptions.beforeBuilderCallback != nil {
|
|
|
- copyBuilder = queryOptions.beforeBuilderCallback(copyBuilder)
|
|
|
- }
|
|
|
+ getRequest := gateway.NewGetRequest(params.ServiceVersionedUrl+domainPath+"/query",
|
|
|
+ gateway.GetRequestWithQueryParamsForm(func(c *api.Context, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (map[string]string, error) {
|
|
|
+ _, err := gateway.FormQueryParamsWithTenantIDAndUserIDFunc("tenantId", "")(c, historyRequest, resultMap)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if queryOptions.beforeBuilderCallback != nil {
|
|
|
+ copyBuilder = queryOptions.beforeBuilderCallback(copyBuilder, c)
|
|
|
+ }
|
|
|
|
|
|
- copyBuilder = copyBuilder.Get(gateway.NewGetRequest(params.ServiceVersionedUrl+domainPath+"/query",
|
|
|
- gateway.GetRequestWithQueryParamsForm(gateway.FormQueryParamsWithTenantIDAndUserIDFunc("tenantId", ""))),
|
|
|
- queryOptions.requestResponseCallback)
|
|
|
+ return c.GetQueryParams().Map(), nil
|
|
|
+ }))
|
|
|
+
|
|
|
+ copyBuilder = copyBuilder.Get(getRequest, queryOptions.requestResponseCallback)
|
|
|
|
|
|
if queryOptions.afterBuilderCallback != nil {
|
|
|
copyBuilder = queryOptions.afterBuilderCallback(copyBuilder)
|
|
|
@@ -162,12 +198,16 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
|
|
|
|
|
|
copyBuilder := builder.Url(http.MethodGet, domainPath+"/get")
|
|
|
|
|
|
- if getByIDOptions.beforeBuilderCallback != nil {
|
|
|
- copyBuilder = getByIDOptions.beforeBuilderCallback(copyBuilder)
|
|
|
- }
|
|
|
+ getRequest := gateway.NewGetRequest(params.ServiceVersionedUrl+domainPath+"/get",
|
|
|
+ gateway.GetRequestWithQueryParamsForm(func(c *api.Context, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (map[string]string, error) {
|
|
|
+ if getByIDOptions.beforeBuilderCallback != nil {
|
|
|
+ copyBuilder = getByIDOptions.beforeBuilderCallback(copyBuilder, c)
|
|
|
+ }
|
|
|
+
|
|
|
+ return c.GetQueryParams().Map(), nil
|
|
|
+ }))
|
|
|
|
|
|
- copyBuilder = copyBuilder.Get(gateway.NewGetRequest(params.ServiceVersionedUrl+domainPath+"/get"),
|
|
|
- getByIDOptions.requestResponseCallback)
|
|
|
+ copyBuilder = copyBuilder.Get(getRequest, getByIDOptions.requestResponseCallback)
|
|
|
|
|
|
if getByIDOptions.afterBuilderCallback != nil {
|
|
|
copyBuilder = getByIDOptions.afterBuilderCallback(copyBuilder)
|
|
|
@@ -177,7 +217,8 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type EntityCRUDBuilderCallback func(builder *gateway.Builder) *gateway.Builder
|
|
|
+type EntityCRUDBeforeCallback func(builder *gateway.Builder, c *api.Context) *gateway.Builder
|
|
|
+type EntityCRUDAfterCallback func(builder *gateway.Builder) *gateway.Builder
|
|
|
|
|
|
type EntityCRUDGlobalOption func(options *EntityCRUDGlobalOptions)
|
|
|
type EntityCRUDCreateOption func(options *EntityCRUDCreateOptions)
|
|
|
@@ -195,13 +236,13 @@ type EntityCRUDCreateOptions struct {
|
|
|
disable bool
|
|
|
|
|
|
// 创建请求前回调
|
|
|
- beforeBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ beforeBuilderCallback EntityCRUDBeforeCallback
|
|
|
|
|
|
// 创建请求响应回调
|
|
|
requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 创建请求后回调
|
|
|
- afterBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ afterBuilderCallback EntityCRUDAfterCallback
|
|
|
|
|
|
// 创建中间件
|
|
|
middlewares []api.Handler
|
|
|
@@ -212,13 +253,13 @@ type EntityCRUDDeleteOptions struct {
|
|
|
disable bool
|
|
|
|
|
|
// 删除请求前回调
|
|
|
- beforeBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ beforeBuilderCallback EntityCRUDBeforeCallback
|
|
|
|
|
|
// 删除请求响应回调
|
|
|
requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 删除请求后回调
|
|
|
- afterBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ afterBuilderCallback EntityCRUDAfterCallback
|
|
|
|
|
|
// 删除中间件
|
|
|
middlewares []api.Handler
|
|
|
@@ -229,13 +270,13 @@ type EntityCRUDUpdateOptions struct {
|
|
|
disable bool
|
|
|
|
|
|
// 更新请求前回调
|
|
|
- beforeBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ beforeBuilderCallback EntityCRUDBeforeCallback
|
|
|
|
|
|
// 更新请求响应回调
|
|
|
requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 更新请求后回调
|
|
|
- afterBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ afterBuilderCallback EntityCRUDAfterCallback
|
|
|
|
|
|
// 更新中间件
|
|
|
middlewares []api.Handler
|
|
|
@@ -246,13 +287,13 @@ type EntityCRUDQueryOptions struct {
|
|
|
disable bool
|
|
|
|
|
|
// 查询请求前回调
|
|
|
- beforeBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ beforeBuilderCallback EntityCRUDBeforeCallback
|
|
|
|
|
|
// 查询请求响应回调
|
|
|
requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 查询请求后回调
|
|
|
- afterBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ afterBuilderCallback EntityCRUDAfterCallback
|
|
|
|
|
|
// 查询中间件
|
|
|
middlewares []api.Handler
|
|
|
@@ -263,13 +304,13 @@ type EntityCRUDGetByIDOptions struct {
|
|
|
disable bool
|
|
|
|
|
|
// 根据ID请求前回调
|
|
|
- beforeBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ beforeBuilderCallback EntityCRUDBeforeCallback
|
|
|
|
|
|
// 根据ID请求响应回调
|
|
|
requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 根据ID请求后回调
|
|
|
- afterBuilderCallback EntityCRUDBuilderCallback
|
|
|
+ afterBuilderCallback EntityCRUDAfterCallback
|
|
|
|
|
|
// 根据ID查询中间件
|
|
|
middlewares []api.Handler
|
|
|
@@ -281,7 +322,7 @@ func WithEntityCRUDGlobalMiddlewares(middlewares ...api.Handler) EntityCRUDGloba
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDBeforeCreateBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDCreateOption {
|
|
|
+func WithEntityCRUDBeforeCreateBuilderCallback(callbacks EntityCRUDBeforeCallback) EntityCRUDCreateOption {
|
|
|
return func(options *EntityCRUDCreateOptions) {
|
|
|
options.beforeBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -293,7 +334,7 @@ func WithEntityCRUDCreateCallbacks(callbacks gateway.RequestResponseCallback) En
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDAfterCreateBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDCreateOption {
|
|
|
+func WithEntityCRUDAfterCreateBuilderCallback(callbacks EntityCRUDAfterCallback) EntityCRUDCreateOption {
|
|
|
return func(options *EntityCRUDCreateOptions) {
|
|
|
options.afterBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -311,7 +352,7 @@ func WithEntityCRUDDisableDelete() EntityCRUDDeleteOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDBeforeDeleteBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDDeleteOption {
|
|
|
+func WithEntityCRUDBeforeDeleteBuilderCallback(callbacks EntityCRUDBeforeCallback) EntityCRUDDeleteOption {
|
|
|
return func(options *EntityCRUDDeleteOptions) {
|
|
|
options.beforeBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -323,7 +364,7 @@ func WithEntityCRUDDeleteCallbacks(callbacks gateway.RequestResponseCallback) En
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDAfterDeleteBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDDeleteOption {
|
|
|
+func WithEntityCRUDAfterDeleteBuilderCallback(callbacks EntityCRUDAfterCallback) EntityCRUDDeleteOption {
|
|
|
return func(options *EntityCRUDDeleteOptions) {
|
|
|
options.afterBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -341,7 +382,7 @@ func WithEntityCRUDDisableUpdate() EntityCRUDUpdateOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDBeforeUpdateBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDUpdateOption {
|
|
|
+func WithEntityCRUDBeforeUpdateBuilderCallback(callbacks EntityCRUDBeforeCallback) EntityCRUDUpdateOption {
|
|
|
return func(options *EntityCRUDUpdateOptions) {
|
|
|
options.beforeBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -353,7 +394,7 @@ func WithEntityCRUDUpdateCallbacks(callbacks gateway.RequestResponseCallback) En
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDAfterUpdateBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDUpdateOption {
|
|
|
+func WithEntityCRUDAfterUpdateBuilderCallback(callbacks EntityCRUDAfterCallback) EntityCRUDUpdateOption {
|
|
|
return func(options *EntityCRUDUpdateOptions) {
|
|
|
options.afterBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -371,7 +412,7 @@ func WithEntityCRUDDisableQuery() EntityCRUDQueryOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDBeforeQueryBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDQueryOption {
|
|
|
+func WithEntityCRUDBeforeQueryBuilderCallback(callbacks EntityCRUDBeforeCallback) EntityCRUDQueryOption {
|
|
|
return func(options *EntityCRUDQueryOptions) {
|
|
|
options.beforeBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -383,7 +424,7 @@ func WithEntityCRUDQueryCallbacks(callbacks gateway.RequestResponseCallback) Ent
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDAfterQueryBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDQueryOption {
|
|
|
+func WithEntityCRUDAfterQueryBuilderCallback(callbacks EntityCRUDAfterCallback) EntityCRUDQueryOption {
|
|
|
return func(options *EntityCRUDQueryOptions) {
|
|
|
options.afterBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -401,7 +442,7 @@ func WithEntityCRUDDisableGetByID() EntityCRUDGetByIDOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDBeforeGetByIDBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDGetByIDOption {
|
|
|
+func WithEntityCRUDBeforeGetByIDBuilderCallback(callbacks EntityCRUDBeforeCallback) EntityCRUDGetByIDOption {
|
|
|
return func(options *EntityCRUDGetByIDOptions) {
|
|
|
options.beforeBuilderCallback = callbacks
|
|
|
}
|
|
|
@@ -413,7 +454,7 @@ func WithEntityCRUDGetByIDCallbacks(callbacks gateway.RequestResponseCallback) E
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithEntityCRUDAfterGetByIDBuilderCallback(callbacks EntityCRUDBuilderCallback) EntityCRUDGetByIDOption {
|
|
|
+func WithEntityCRUDAfterGetByIDBuilderCallback(callbacks EntityCRUDAfterCallback) EntityCRUDGetByIDOption {
|
|
|
return func(options *EntityCRUDGetByIDOptions) {
|
|
|
options.afterBuilderCallback = callbacks
|
|
|
}
|