|
@@ -52,88 +52,88 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
domainPath := domain.RelativeDomainPath(simple.Entity)
|
|
domainPath := domain.RelativeDomainPath(simple.Entity)
|
|
|
|
|
|
|
|
// 创建
|
|
// 创建
|
|
|
- if !createOptions.disableCreate {
|
|
|
|
|
- if !createOptions.createNeedTx {
|
|
|
|
|
|
|
+ if !createOptions.disable {
|
|
|
|
|
+ if !createOptions.needTx {
|
|
|
binding.PostBind[string](binder, &binding.SimpleBindItem[string]{
|
|
binding.PostBind[string](binder, &binding.SimpleBindItem[string]{
|
|
|
Path: domainPath + "/create",
|
|
Path: domainPath + "/create",
|
|
|
ResponseFunc: response.SendIDResponse,
|
|
ResponseFunc: response.SendIDResponse,
|
|
|
RequestParams: simple.CreateJsonBody,
|
|
RequestParams: simple.CreateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Create(tableName, createOptions.createCallbacks),
|
|
|
|
|
- }, createOptions.createMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: Create(tableName, createOptions.callbacks),
|
|
|
|
|
+ }, createOptions.middlewares...)
|
|
|
} else {
|
|
} else {
|
|
|
binding.PostBind(binder, &binding.SimpleBindItem[string]{
|
|
binding.PostBind(binder, &binding.SimpleBindItem[string]{
|
|
|
Path: domainPath + "/create",
|
|
Path: domainPath + "/create",
|
|
|
ResponseFunc: response.SendIDResponse,
|
|
ResponseFunc: response.SendIDResponse,
|
|
|
RequestParams: simple.CreateJsonBody,
|
|
RequestParams: simple.CreateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: CreateTx(tableName, createOptions.createCallbacks),
|
|
|
|
|
- }, createOptions.createMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: CreateTx(tableName, createOptions.callbacks),
|
|
|
|
|
+ }, createOptions.middlewares...)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 删除
|
|
// 删除
|
|
|
- if !deleteOptions.disableDelete {
|
|
|
|
|
- if !deleteOptions.deleteNeedTx {
|
|
|
|
|
|
|
+ if !deleteOptions.disable {
|
|
|
|
|
+ if !deleteOptions.needTx {
|
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/delete",
|
|
Path: domainPath + "/delete",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.DeleteQueryParams,
|
|
RequestParams: simple.DeleteQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Delete(tableName, deleteOptions.deleteCallbacks),
|
|
|
|
|
- }, deleteOptions.deleteMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: Delete(tableName, deleteOptions.callbacks),
|
|
|
|
|
+ }, deleteOptions.middlewares...)
|
|
|
} else {
|
|
} else {
|
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/delete",
|
|
Path: domainPath + "/delete",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.DeleteQueryParams,
|
|
RequestParams: simple.DeleteQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: DeleteTx(tableName, deleteOptions.deleteCallbacks),
|
|
|
|
|
- }, deleteOptions.deleteMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: DeleteTx(tableName, deleteOptions.callbacks),
|
|
|
|
|
+ }, deleteOptions.middlewares...)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 修改
|
|
// 修改
|
|
|
- if !updateOptions.disableUpdate {
|
|
|
|
|
- if !updateOptions.updateNeedTx {
|
|
|
|
|
|
|
+ if !updateOptions.disable {
|
|
|
|
|
+ if !updateOptions.needTx {
|
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/update",
|
|
Path: domainPath + "/update",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.UpdateJsonBody,
|
|
RequestParams: simple.UpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Update(tableName, updateOptions.updateCallbacks),
|
|
|
|
|
- }, updateOptions.updateMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: Update(tableName, updateOptions.callbacks),
|
|
|
|
|
+ }, updateOptions.middlewares...)
|
|
|
} else {
|
|
} else {
|
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/update",
|
|
Path: domainPath + "/update",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.UpdateJsonBody,
|
|
RequestParams: simple.UpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: UpdateTx(tableName, updateOptions.updateCallbacks),
|
|
|
|
|
- }, updateOptions.updateMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: UpdateTx(tableName, updateOptions.callbacks),
|
|
|
|
|
+ }, updateOptions.middlewares...)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 查询
|
|
// 查询
|
|
|
- if !queryOptions.disableQuery {
|
|
|
|
|
|
|
+ if !queryOptions.disable {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
|
Path: domainPath + "/query",
|
|
Path: domainPath + "/query",
|
|
|
ResponseFunc: response.SendInfosResponse[I],
|
|
ResponseFunc: response.SendInfosResponse[I],
|
|
|
RequestParams: simple.QueryQueryParams,
|
|
RequestParams: simple.QueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Query[I](tableName, queryOptions.queryCallbacks, queryOptions.queryConditionFieldCallback),
|
|
|
|
|
- }, queryOptions.queryMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: Query[I](tableName, queryOptions.callbacks, queryOptions.conditionFieldCallback),
|
|
|
|
|
+ }, queryOptions.middlewares...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 通过ID获取
|
|
// 通过ID获取
|
|
|
- if !getByIDOptions.disableGetByID {
|
|
|
|
|
|
|
+ if !getByIDOptions.disable {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[I]{
|
|
binding.GetBind(binder, &binding.SimpleBindItem[I]{
|
|
|
Path: domainPath + "/get",
|
|
Path: domainPath + "/get",
|
|
|
ResponseFunc: response.SendInfoResponse[I],
|
|
ResponseFunc: response.SendInfoResponse[I],
|
|
|
RequestParams: simple.GetByIDQueryParams,
|
|
RequestParams: simple.GetByIDQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: GetByID[I](tableName, getByIDOptions.getByIDCallbacks),
|
|
|
|
|
- }, getByIDOptions.getByIDMiddlewares...)
|
|
|
|
|
|
|
+ ServiceFunc: GetByID[I](tableName, getByIDOptions.callbacks),
|
|
|
|
|
+ }, getByIDOptions.middlewares...)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -178,181 +178,181 @@ type GetByIDOption[I any] func(options *GetByIDOptions[I])
|
|
|
|
|
|
|
|
type CreateOptions struct {
|
|
type CreateOptions struct {
|
|
|
// 关闭创建
|
|
// 关闭创建
|
|
|
- disableCreate bool
|
|
|
|
|
|
|
+ disable bool
|
|
|
|
|
|
|
|
// 创建是否使用事务
|
|
// 创建是否使用事务
|
|
|
- createNeedTx bool
|
|
|
|
|
|
|
+ needTx bool
|
|
|
|
|
|
|
|
// 创建回调
|
|
// 创建回调
|
|
|
- createCallbacks *CreateCallbacks
|
|
|
|
|
|
|
+ callbacks *CreateCallbacks
|
|
|
|
|
|
|
|
// 创建中间件
|
|
// 创建中间件
|
|
|
- createMiddlewares []api.Handler
|
|
|
|
|
|
|
+ middlewares []api.Handler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type DeleteOptions struct {
|
|
type DeleteOptions struct {
|
|
|
// 关闭删除
|
|
// 关闭删除
|
|
|
- disableDelete bool
|
|
|
|
|
|
|
+ disable bool
|
|
|
|
|
|
|
|
// 删除是否使用事务
|
|
// 删除是否使用事务
|
|
|
- deleteNeedTx bool
|
|
|
|
|
|
|
+ needTx bool
|
|
|
|
|
|
|
|
// 删除回调
|
|
// 删除回调
|
|
|
- deleteCallbacks *DeleteCallbacks
|
|
|
|
|
|
|
+ callbacks *DeleteCallbacks
|
|
|
|
|
|
|
|
// 删除中间件
|
|
// 删除中间件
|
|
|
- deleteMiddlewares []api.Handler
|
|
|
|
|
|
|
+ middlewares []api.Handler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type UpdateOptions struct {
|
|
type UpdateOptions struct {
|
|
|
// 关闭更新
|
|
// 关闭更新
|
|
|
- disableUpdate bool
|
|
|
|
|
|
|
+ disable bool
|
|
|
|
|
|
|
|
// 更新是否使用事务
|
|
// 更新是否使用事务
|
|
|
- updateNeedTx bool
|
|
|
|
|
|
|
+ needTx bool
|
|
|
|
|
|
|
|
// 更新回调
|
|
// 更新回调
|
|
|
- updateCallbacks *UpdateCallbacks
|
|
|
|
|
|
|
+ callbacks *UpdateCallbacks
|
|
|
|
|
|
|
|
// 更新中间件
|
|
// 更新中间件
|
|
|
- updateMiddlewares []api.Handler
|
|
|
|
|
|
|
+ middlewares []api.Handler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type QueryOptions[I any] struct {
|
|
type QueryOptions[I any] struct {
|
|
|
// 关闭查询
|
|
// 关闭查询
|
|
|
- disableQuery bool
|
|
|
|
|
|
|
+ disable bool
|
|
|
|
|
|
|
|
// 查询条件构造回调
|
|
// 查询条件构造回调
|
|
|
- queryConditionFieldCallback ConditionFieldCallback
|
|
|
|
|
|
|
+ conditionFieldCallback ConditionFieldCallback
|
|
|
|
|
|
|
|
// 查询回调
|
|
// 查询回调
|
|
|
- queryCallbacks *QueryCallbacks[I]
|
|
|
|
|
|
|
+ callbacks *QueryCallbacks[I]
|
|
|
|
|
|
|
|
// 查询中间件
|
|
// 查询中间件
|
|
|
- queryMiddlewares []api.Handler
|
|
|
|
|
|
|
+ middlewares []api.Handler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type GetByIDOptions[I any] struct {
|
|
type GetByIDOptions[I any] struct {
|
|
|
// 关闭根据ID查询
|
|
// 关闭根据ID查询
|
|
|
- disableGetByID bool
|
|
|
|
|
|
|
+ disable bool
|
|
|
|
|
|
|
|
// 根据ID查询回调
|
|
// 根据ID查询回调
|
|
|
- getByIDCallbacks *GetByIDCallbacks[I]
|
|
|
|
|
|
|
+ callbacks *GetByIDCallbacks[I]
|
|
|
|
|
|
|
|
// 根据ID查询中间件
|
|
// 根据ID查询中间件
|
|
|
- getByIDMiddlewares []api.Handler
|
|
|
|
|
|
|
+ middlewares []api.Handler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDisableCreate() CreateOption {
|
|
func WithDisableCreate() CreateOption {
|
|
|
return func(options *CreateOptions) {
|
|
return func(options *CreateOptions) {
|
|
|
- options.disableCreate = true
|
|
|
|
|
|
|
+ options.disable = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithCreateTx() CreateOption {
|
|
func WithCreateTx() CreateOption {
|
|
|
return func(options *CreateOptions) {
|
|
return func(options *CreateOptions) {
|
|
|
- options.createNeedTx = true
|
|
|
|
|
|
|
+ options.needTx = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithCreateCallbacks(callbacks *CreateCallbacks) CreateOption {
|
|
func WithCreateCallbacks(callbacks *CreateCallbacks) CreateOption {
|
|
|
return func(options *CreateOptions) {
|
|
return func(options *CreateOptions) {
|
|
|
- options.createCallbacks = callbacks
|
|
|
|
|
|
|
+ options.callbacks = callbacks
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithCreateMiddlewares(middlewares []api.Handler) CreateOption {
|
|
func WithCreateMiddlewares(middlewares []api.Handler) CreateOption {
|
|
|
return func(options *CreateOptions) {
|
|
return func(options *CreateOptions) {
|
|
|
- options.createMiddlewares = middlewares
|
|
|
|
|
|
|
+ options.middlewares = middlewares
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDisableDelete() DeleteOption {
|
|
func WithDisableDelete() DeleteOption {
|
|
|
return func(options *DeleteOptions) {
|
|
return func(options *DeleteOptions) {
|
|
|
- options.disableDelete = true
|
|
|
|
|
|
|
+ options.disable = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDeleteTx() DeleteOption {
|
|
func WithDeleteTx() DeleteOption {
|
|
|
return func(options *DeleteOptions) {
|
|
return func(options *DeleteOptions) {
|
|
|
- options.deleteNeedTx = true
|
|
|
|
|
|
|
+ options.needTx = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDeleteCallbacks(callbacks *DeleteCallbacks) DeleteOption {
|
|
func WithDeleteCallbacks(callbacks *DeleteCallbacks) DeleteOption {
|
|
|
return func(options *DeleteOptions) {
|
|
return func(options *DeleteOptions) {
|
|
|
- options.deleteCallbacks = callbacks
|
|
|
|
|
|
|
+ options.callbacks = callbacks
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDeleteMiddlewares(middlewares []api.Handler) DeleteOption {
|
|
func WithDeleteMiddlewares(middlewares []api.Handler) DeleteOption {
|
|
|
return func(options *DeleteOptions) {
|
|
return func(options *DeleteOptions) {
|
|
|
- options.deleteMiddlewares = middlewares
|
|
|
|
|
|
|
+ options.middlewares = middlewares
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDisableUpdate() UpdateOption {
|
|
func WithDisableUpdate() UpdateOption {
|
|
|
return func(options *UpdateOptions) {
|
|
return func(options *UpdateOptions) {
|
|
|
- options.disableUpdate = true
|
|
|
|
|
|
|
+ options.disable = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithUpdateTx() UpdateOption {
|
|
func WithUpdateTx() UpdateOption {
|
|
|
return func(options *UpdateOptions) {
|
|
return func(options *UpdateOptions) {
|
|
|
- options.updateNeedTx = true
|
|
|
|
|
|
|
+ options.needTx = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithUpdateCallbacks(callbacks *UpdateCallbacks) UpdateOption {
|
|
func WithUpdateCallbacks(callbacks *UpdateCallbacks) UpdateOption {
|
|
|
return func(options *UpdateOptions) {
|
|
return func(options *UpdateOptions) {
|
|
|
- options.updateCallbacks = callbacks
|
|
|
|
|
|
|
+ options.callbacks = callbacks
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithUpdateMiddlewares(middlewares []api.Handler) UpdateOption {
|
|
func WithUpdateMiddlewares(middlewares []api.Handler) UpdateOption {
|
|
|
return func(options *UpdateOptions) {
|
|
return func(options *UpdateOptions) {
|
|
|
- options.updateMiddlewares = middlewares
|
|
|
|
|
|
|
+ options.middlewares = middlewares
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDisableQuery[I any]() QueryOption[I] {
|
|
func WithDisableQuery[I any]() QueryOption[I] {
|
|
|
return func(options *QueryOptions[I]) {
|
|
return func(options *QueryOptions[I]) {
|
|
|
- options.disableQuery = true
|
|
|
|
|
|
|
+ options.disable = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithQueryConditionFieldCallback[I any](callback ConditionFieldCallback) QueryOption[I] {
|
|
func WithQueryConditionFieldCallback[I any](callback ConditionFieldCallback) QueryOption[I] {
|
|
|
return func(options *QueryOptions[I]) {
|
|
return func(options *QueryOptions[I]) {
|
|
|
- options.queryConditionFieldCallback = callback
|
|
|
|
|
|
|
+ options.conditionFieldCallback = callback
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithQueryCallbacks[I any](callbacks *QueryCallbacks[I]) QueryOption[I] {
|
|
func WithQueryCallbacks[I any](callbacks *QueryCallbacks[I]) QueryOption[I] {
|
|
|
return func(options *QueryOptions[I]) {
|
|
return func(options *QueryOptions[I]) {
|
|
|
- options.queryCallbacks = callbacks
|
|
|
|
|
|
|
+ options.callbacks = callbacks
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithQueryMiddlewares[I any](middlewares []api.Handler) QueryOption[I] {
|
|
func WithQueryMiddlewares[I any](middlewares []api.Handler) QueryOption[I] {
|
|
|
return func(options *QueryOptions[I]) {
|
|
return func(options *QueryOptions[I]) {
|
|
|
- options.queryMiddlewares = middlewares
|
|
|
|
|
|
|
+ options.middlewares = middlewares
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithDisableGetByID[I any]() GetByIDOption[I] {
|
|
func WithDisableGetByID[I any]() GetByIDOption[I] {
|
|
|
return func(options *GetByIDOptions[I]) {
|
|
return func(options *GetByIDOptions[I]) {
|
|
|
- options.disableGetByID = true
|
|
|
|
|
|
|
+ options.disable = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithGetByIDCallbacks[I any](callbacks *GetByIDCallbacks[I]) GetByIDOption[I] {
|
|
func WithGetByIDCallbacks[I any](callbacks *GetByIDCallbacks[I]) GetByIDOption[I] {
|
|
|
return func(options *GetByIDOptions[I]) {
|
|
return func(options *GetByIDOptions[I]) {
|
|
|
- options.getByIDCallbacks = callbacks
|
|
|
|
|
|
|
+ options.callbacks = callbacks
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func WithGetByIDMiddlewares[I any](middlewares []api.Handler) GetByIDOption[I] {
|
|
func WithGetByIDMiddlewares[I any](middlewares []api.Handler) GetByIDOption[I] {
|
|
|
return func(options *GetByIDOptions[I]) {
|
|
return func(options *GetByIDOptions[I]) {
|
|
|
- options.getByIDMiddlewares = middlewares
|
|
|
|
|
|
|
+ options.middlewares = middlewares
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|