|
|
@@ -1,12 +1,13 @@
|
|
|
package entity_crud
|
|
|
|
|
|
import (
|
|
|
+ "net/http"
|
|
|
+
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/api/response"
|
|
|
"git.sxidc.com/go-framework/baize/framework/gateway"
|
|
|
"git.sxidc.com/go-tools/utils/http_client"
|
|
|
"git.sxidc.com/go-tools/utils/template"
|
|
|
"github.com/iancoleman/strcase"
|
|
|
- "net/http"
|
|
|
)
|
|
|
|
|
|
func BindSimple(builder *gateway.Builder, params *Simple, opts ...any) {
|
|
|
@@ -79,7 +80,7 @@ func (simple *Simple) bind(builder *gateway.Builder) {
|
|
|
if !createOptions.disable {
|
|
|
createMiddlewares := append(globalOptions.middlewares, createOptions.middlewares...)
|
|
|
|
|
|
- builder.PostRouteWithTenantIDAndCreateUserInfo("/"+simple.ServiceShortName+domainPath+"/create",
|
|
|
+ builder.PostRouteWithTenantIDAndCreateUserInfo("/"+simple.ServiceShortName+domainPath+"/create"+createOptions.urlPattern,
|
|
|
func(requestBuilder *gateway.RequestBuilder) {
|
|
|
if createOptions.responseSuccessCallback != nil {
|
|
|
requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
|
|
|
@@ -136,7 +137,7 @@ func (simple *Simple) bind(builder *gateway.Builder) {
|
|
|
if !deleteOptions.disable {
|
|
|
deleteMiddlewares := append(globalOptions.middlewares, deleteOptions.middlewares...)
|
|
|
|
|
|
- builder.DeleteRouteWithDeleteUserInfo("/"+simple.ServiceShortName+domainPath+"/delete",
|
|
|
+ builder.DeleteRouteWithDeleteUserInfo("/"+simple.ServiceShortName+domainPath+"/delete"+deleteOptions.urlPattern,
|
|
|
func(requestBuilder *gateway.RequestBuilder) {
|
|
|
if deleteOptions.responseSuccessCallback != nil {
|
|
|
requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
|
|
|
@@ -193,7 +194,7 @@ func (simple *Simple) bind(builder *gateway.Builder) {
|
|
|
if !updateOptions.disable {
|
|
|
updateMiddlewares := append(globalOptions.middlewares, updateOptions.middlewares...)
|
|
|
|
|
|
- builder.PutRouteWithUpdateUserInfo("/"+simple.ServiceShortName+domainPath+"/update",
|
|
|
+ builder.PutRouteWithUpdateUserInfo("/"+simple.ServiceShortName+domainPath+"/update"+updateOptions.urlPattern,
|
|
|
func(requestBuilder *gateway.RequestBuilder) {
|
|
|
if updateOptions.responseSuccessCallback != nil {
|
|
|
requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
|
|
|
@@ -249,7 +250,7 @@ func (simple *Simple) bind(builder *gateway.Builder) {
|
|
|
if !queryOptions.disable {
|
|
|
queryMiddlewares := append(globalOptions.middlewares, queryOptions.middlewares...)
|
|
|
|
|
|
- builder.GetRouteWithTenantID("/"+simple.ServiceShortName+domainPath+"/query",
|
|
|
+ builder.GetRouteWithTenantID("/"+simple.ServiceShortName+domainPath+"/query"+queryOptions.urlPattern,
|
|
|
func(requestBuilder *gateway.RequestBuilder) {
|
|
|
if queryOptions.responseSuccessCallback != nil {
|
|
|
requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
|
|
|
@@ -305,7 +306,7 @@ func (simple *Simple) bind(builder *gateway.Builder) {
|
|
|
if !getByIDOptions.disable {
|
|
|
getByIDMiddlewares := append(globalOptions.middlewares, getByIDOptions.middlewares...)
|
|
|
|
|
|
- builder.GetRoute("/"+simple.ServiceShortName+domainPath+"/get",
|
|
|
+ builder.GetRoute("/"+simple.ServiceShortName+domainPath+"/get"+getByIDOptions.urlPattern,
|
|
|
func(requestBuilder *gateway.RequestBuilder) {
|
|
|
if getByIDOptions.responseSuccessCallback != nil {
|
|
|
requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
|
|
|
@@ -370,7 +371,8 @@ type QueryOption func(options *QueryOptions)
|
|
|
type GetByIDOption func(options *GetByIDOptions)
|
|
|
|
|
|
type GlobalOptions struct {
|
|
|
- middlewares []gateway.Handler
|
|
|
+ middlewares []gateway.Handler
|
|
|
+ disableUrlPattern bool
|
|
|
}
|
|
|
|
|
|
type CreateOptions struct {
|
|
|
@@ -391,6 +393,9 @@ type CreateOptions struct {
|
|
|
|
|
|
// 创建中间件
|
|
|
middlewares []gateway.Handler
|
|
|
+
|
|
|
+ // url模式
|
|
|
+ urlPattern string
|
|
|
}
|
|
|
|
|
|
type DeleteOptions struct {
|
|
|
@@ -411,6 +416,9 @@ type DeleteOptions struct {
|
|
|
|
|
|
// 删除中间件
|
|
|
middlewares []gateway.Handler
|
|
|
+
|
|
|
+ // url模式
|
|
|
+ urlPattern string
|
|
|
}
|
|
|
|
|
|
type UpdateOptions struct {
|
|
|
@@ -431,6 +439,9 @@ type UpdateOptions struct {
|
|
|
|
|
|
// 更新中间件
|
|
|
middlewares []gateway.Handler
|
|
|
+
|
|
|
+ // url模式
|
|
|
+ urlPattern string
|
|
|
}
|
|
|
|
|
|
type QueryOptions struct {
|
|
|
@@ -451,6 +462,9 @@ type QueryOptions struct {
|
|
|
|
|
|
// 查询中间件
|
|
|
middlewares []gateway.Handler
|
|
|
+
|
|
|
+ // url模式
|
|
|
+ urlPattern string
|
|
|
}
|
|
|
|
|
|
type GetByIDOptions struct {
|
|
|
@@ -471,6 +485,9 @@ type GetByIDOptions struct {
|
|
|
|
|
|
// 根据ID查询中间件
|
|
|
middlewares []gateway.Handler
|
|
|
+
|
|
|
+ // url模式
|
|
|
+ urlPattern string
|
|
|
}
|
|
|
|
|
|
func WithGlobalMiddlewares(middlewares ...gateway.Handler) GlobalOption {
|
|
|
@@ -515,6 +532,12 @@ func WithCreateMiddlewares(middlewares ...gateway.Handler) CreateOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func WithCreateUrlPattern(urlPattern string) CreateOption {
|
|
|
+ return func(options *CreateOptions) {
|
|
|
+ options.urlPattern = urlPattern
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func WithDisableDelete() DeleteOption {
|
|
|
return func(options *DeleteOptions) {
|
|
|
options.disable = true
|
|
|
@@ -551,6 +574,12 @@ func WithDeleteMiddlewares(middlewares ...gateway.Handler) DeleteOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func WithDeleteUrlPattern(urlPattern string) DeleteOption {
|
|
|
+ return func(options *DeleteOptions) {
|
|
|
+ options.urlPattern = urlPattern
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func WithDisableUpdate() UpdateOption {
|
|
|
return func(options *UpdateOptions) {
|
|
|
options.disable = true
|
|
|
@@ -587,6 +616,12 @@ func WithUpdateMiddlewares(middlewares ...gateway.Handler) UpdateOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func WithUpdateUrlPattern(urlPattern string) UpdateOption {
|
|
|
+ return func(options *UpdateOptions) {
|
|
|
+ options.urlPattern = urlPattern
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func WithDisableQuery() QueryOption {
|
|
|
return func(options *QueryOptions) {
|
|
|
options.disable = true
|
|
|
@@ -623,6 +658,12 @@ func WithQueryMiddlewares(middlewares ...gateway.Handler) QueryOption {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func WithQueryUrlPattern(urlPattern string) QueryOption {
|
|
|
+ return func(options *QueryOptions) {
|
|
|
+ options.urlPattern = urlPattern
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func WithDisableGetByID() GetByIDOption {
|
|
|
return func(options *GetByIDOptions) {
|
|
|
options.disable = true
|
|
|
@@ -658,3 +699,9 @@ func WithGetByIDMiddlewares(middlewares ...gateway.Handler) GetByIDOption {
|
|
|
options.middlewares = middlewares
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func WithGetByIDUrlPattern(urlPattern string) GetByIDOption {
|
|
|
+ return func(options *GetByIDOptions) {
|
|
|
+ options.urlPattern = urlPattern
|
|
|
+ }
|
|
|
+}
|