|
|
@@ -69,11 +69,17 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
|
|
|
if !createOptions.disable {
|
|
|
builder.
|
|
|
Url(http.MethodPost, domainPath+"/create").
|
|
|
- Post(&gateway.PostRequest{
|
|
|
- Url: params.ServiceVersionedUrl + domainPath + "/create",
|
|
|
- Body: AddBodyTenantIDAndUserID("tenantId", "createUserId",
|
|
|
- params.createOptions.getTenantIDFunc, params.createOptions.getUserIDFunc),
|
|
|
- }, createOptions.callback).
|
|
|
+ Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
|
|
|
+ newBody, err := gateway.AddJsonBodyTenantIDAndUserID(c, "tenantId", "createUserId")
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &gateway.PostRequest{
|
|
|
+ Url: params.ServiceVersionedUrl + domainPath + "/create",
|
|
|
+ Body: newBody,
|
|
|
+ }, nil
|
|
|
+ }, createOptions.requestResponseCallback).
|
|
|
Build(createOptions.middlewares...)
|
|
|
}
|
|
|
|
|
|
@@ -83,7 +89,7 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
|
|
|
Url(http.MethodDelete, domainPath+"/delete").
|
|
|
Delete(&gateway.DeleteRequest{
|
|
|
Url: params.ServiceVersionedUrl + domainPath + "/delete",
|
|
|
- }, deleteOptions.callback).
|
|
|
+ }, deleteOptions.requestResponseCallback).
|
|
|
Build(deleteOptions.middlewares...)
|
|
|
}
|
|
|
|
|
|
@@ -91,11 +97,17 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
|
|
|
if !updateOptions.disable {
|
|
|
builder.
|
|
|
Url(http.MethodPut, domainPath+"/update").
|
|
|
- Put(&gateway.PutRequest{
|
|
|
- Url: params.ServiceVersionedUrl + domainPath + "/update",
|
|
|
- Body: AddBodyTenantIDAndUserID("", "updateUserId",
|
|
|
- nil, params.updateOptions.getUserIDFunc),
|
|
|
- }, updateOptions.callback).
|
|
|
+ Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
|
|
|
+ newBody, err := gateway.AddJsonBodyTenantIDAndUserID(c, "", "updateUserId")
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &gateway.PutRequest{
|
|
|
+ Url: params.ServiceVersionedUrl + domainPath + "/update",
|
|
|
+ Body: newBody,
|
|
|
+ }, nil
|
|
|
+ }, updateOptions.requestResponseCallback).
|
|
|
Build(updateOptions.middlewares...)
|
|
|
}
|
|
|
|
|
|
@@ -103,11 +115,17 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
|
|
|
if !queryOptions.disable {
|
|
|
builder.
|
|
|
Url(http.MethodGet, domainPath+"/query").
|
|
|
- Get(&gateway.GetRequest{
|
|
|
- Url: params.ServiceVersionedUrl + domainPath + "/query",
|
|
|
- QueryParams: AddQueryParamsTenantIDAndUserID("tenantId", "",
|
|
|
- params.queryOptions.getTenantIDFunc, nil),
|
|
|
- }, queryOptions.callback).
|
|
|
+ Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
|
|
|
+ newQueryParams, err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &gateway.GetRequest{
|
|
|
+ Url: params.ServiceVersionedUrl + domainPath + "/query",
|
|
|
+ QueryParams: newQueryParams,
|
|
|
+ }, nil
|
|
|
+ }, updateOptions.requestResponseCallback).
|
|
|
Build(queryOptions.middlewares...)
|
|
|
}
|
|
|
|
|
|
@@ -117,7 +135,7 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
|
|
|
Url(http.MethodGet, domainPath+"/get").
|
|
|
Get(&gateway.GetRequest{
|
|
|
Url: params.ServiceVersionedUrl + domainPath + "/get",
|
|
|
- }, getByIDOptions.callback).
|
|
|
+ }, getByIDOptions.requestResponseCallback).
|
|
|
Build(getByIDOptions.middlewares...)
|
|
|
}
|
|
|
}
|
|
|
@@ -132,25 +150,19 @@ type CRUDCreateOptions struct {
|
|
|
// 关闭创建
|
|
|
disable bool
|
|
|
|
|
|
- // 创建回调
|
|
|
- callback gateway.RequestCallback
|
|
|
+ // 创建请求响应回调
|
|
|
+ requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 创建中间件
|
|
|
middlewares []api.Handler
|
|
|
-
|
|
|
- // 获取租户ID的接口
|
|
|
- getTenantIDFunc GetTenantInfoFunc
|
|
|
-
|
|
|
- // 获取用户ID的接口
|
|
|
- getUserIDFunc GetUserInfoFunc
|
|
|
}
|
|
|
|
|
|
type CRUDDeleteOptions struct {
|
|
|
// 关闭删除
|
|
|
disable bool
|
|
|
|
|
|
- // 删除回调
|
|
|
- callback gateway.RequestCallback
|
|
|
+ // 删除请求响应回调
|
|
|
+ requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 删除中间件
|
|
|
middlewares []api.Handler
|
|
|
@@ -160,44 +172,38 @@ type CRUDUpdateOptions struct {
|
|
|
// 关闭更新
|
|
|
disable bool
|
|
|
|
|
|
- // 更新回调
|
|
|
- callback gateway.RequestCallback
|
|
|
+ // 更新请求响应回调
|
|
|
+ requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 更新中间件
|
|
|
middlewares []api.Handler
|
|
|
-
|
|
|
- // 获取用户ID的接口
|
|
|
- getUserIDFunc GetUserInfoFunc
|
|
|
}
|
|
|
|
|
|
type CRUDQueryOptions struct {
|
|
|
// 关闭查询
|
|
|
disable bool
|
|
|
|
|
|
- // 查询回调
|
|
|
- callback gateway.RequestCallback
|
|
|
+ // 查询请求响应回调
|
|
|
+ requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 查询中间件
|
|
|
middlewares []api.Handler
|
|
|
-
|
|
|
- // 获取租户ID的接口
|
|
|
- getTenantIDFunc GetTenantInfoFunc
|
|
|
}
|
|
|
|
|
|
type CRUDGetByIDOptions struct {
|
|
|
// 关闭根据ID查询
|
|
|
disable bool
|
|
|
|
|
|
- // 根据ID查询回调
|
|
|
- callback gateway.RequestCallback
|
|
|
+ // 根据ID请求响应回调
|
|
|
+ requestResponseCallback gateway.RequestResponseCallback
|
|
|
|
|
|
// 根据ID查询中间件
|
|
|
middlewares []api.Handler
|
|
|
}
|
|
|
|
|
|
-func WithCRUDCreateCallbacks(callbacks gateway.RequestCallback) CRUDCreateOption {
|
|
|
+func WithCRUDCreateCallbacks(callbacks gateway.RequestResponseCallback) CRUDCreateOption {
|
|
|
return func(options *CRUDCreateOptions) {
|
|
|
- options.callback = callbacks
|
|
|
+ options.requestResponseCallback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -207,27 +213,15 @@ func WithCRUDCreateMiddlewares(middlewares []api.Handler) CRUDCreateOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCRUDCreateGetTenantIDFunc(getTenantIDFunc GetTenantInfoFunc) CRUDCreateOption {
|
|
|
- return func(options *CRUDCreateOptions) {
|
|
|
- options.getTenantIDFunc = getTenantIDFunc
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func WithCRUDCreateGetUserIDFunc(getUserIDFunc GetUserInfoFunc) CRUDCreateOption {
|
|
|
- return func(options *CRUDCreateOptions) {
|
|
|
- options.getUserIDFunc = getUserIDFunc
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func WithCRUDDisableDelete() CRUDDeleteOption {
|
|
|
return func(options *CRUDDeleteOptions) {
|
|
|
options.disable = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCRUDDeleteCallbacks(callbacks gateway.RequestCallback) CRUDDeleteOption {
|
|
|
+func WithCRUDDeleteCallbacks(callbacks gateway.RequestResponseCallback) CRUDDeleteOption {
|
|
|
return func(options *CRUDDeleteOptions) {
|
|
|
- options.callback = callbacks
|
|
|
+ options.requestResponseCallback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -243,9 +237,9 @@ func WithCRUDDisableUpdate() CRUDUpdateOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCRUDUpdateCallbacks(callbacks gateway.RequestCallback) CRUDUpdateOption {
|
|
|
+func WithCRUDUpdateCallbacks(callbacks gateway.RequestResponseCallback) CRUDUpdateOption {
|
|
|
return func(options *CRUDUpdateOptions) {
|
|
|
- options.callback = callbacks
|
|
|
+ options.requestResponseCallback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -255,21 +249,15 @@ func WithCRUDUpdateMiddlewares(middlewares []api.Handler) CRUDUpdateOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCRUDUpdateGetUserIDFunc(getUserIDFunc GetUserInfoFunc) CRUDUpdateOption {
|
|
|
- return func(options *CRUDUpdateOptions) {
|
|
|
- options.getUserIDFunc = getUserIDFunc
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func WithCRUDDisableQuery() CRUDQueryOption {
|
|
|
return func(options *CRUDQueryOptions) {
|
|
|
options.disable = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCRUDQueryCallbacks(callbacks gateway.RequestCallback) CRUDQueryOption {
|
|
|
+func WithCRUDQueryCallbacks(callbacks gateway.RequestResponseCallback) CRUDQueryOption {
|
|
|
return func(options *CRUDQueryOptions) {
|
|
|
- options.callback = callbacks
|
|
|
+ options.requestResponseCallback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -279,21 +267,15 @@ func WithCRUDQueryMiddlewares(middlewares []api.Handler) CRUDQueryOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCRUDQueryGetTenantIDFunc(getTenantIDFunc GetTenantInfoFunc) CRUDQueryOption {
|
|
|
- return func(options *CRUDQueryOptions) {
|
|
|
- options.getTenantIDFunc = getTenantIDFunc
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func WithCRUDDisableGetByID() CRUDGetByIDOption {
|
|
|
return func(options *CRUDGetByIDOptions) {
|
|
|
options.disable = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCRUDGetByIDCallbacks(callbacks gateway.RequestCallback) CRUDGetByIDOption {
|
|
|
+func WithCRUDGetByIDCallbacks(callbacks gateway.RequestResponseCallback) CRUDGetByIDOption {
|
|
|
return func(options *CRUDGetByIDOptions) {
|
|
|
- options.callback = callbacks
|
|
|
+ options.requestResponseCallback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|