|
|
@@ -40,7 +40,7 @@ type Simple[I any] struct {
|
|
|
getByIDOptions *GetByIDOptions[I]
|
|
|
}
|
|
|
|
|
|
-func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
+func (simple *Simple[I]) bind(binder *binding.Binder, middlewares ...binding.Middleware) {
|
|
|
createOptions := simple.createOptions
|
|
|
deleteOptions := simple.deleteOptions
|
|
|
updateOptions := simple.updateOptions
|
|
|
@@ -52,6 +52,8 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
|
|
|
// 创建
|
|
|
if !createOptions.disable {
|
|
|
+ createMiddlewares := append(middlewares, createOptions.middlewares...)
|
|
|
+
|
|
|
if !createOptions.needTx {
|
|
|
binding.PostBind[string](binder, &binding.SimpleBindItem[string]{
|
|
|
Path: domainPath + "/create",
|
|
|
@@ -59,7 +61,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.CreateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: Create(tableName, createOptions.callbacks),
|
|
|
- }, createOptions.middlewares...)
|
|
|
+ }, createMiddlewares...)
|
|
|
} else {
|
|
|
binding.PostBind(binder, &binding.SimpleBindItem[string]{
|
|
|
Path: domainPath + "/create",
|
|
|
@@ -67,12 +69,14 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.CreateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: CreateTx(tableName, createOptions.callbacks),
|
|
|
- }, createOptions.middlewares...)
|
|
|
+ }, createMiddlewares...)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 删除
|
|
|
if !deleteOptions.disable {
|
|
|
+ deleteMiddlewares := append(middlewares, deleteOptions.middlewares...)
|
|
|
+
|
|
|
if !deleteOptions.needTx {
|
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/delete",
|
|
|
@@ -80,7 +84,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.DeleteQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: Delete(tableName, deleteOptions.callbacks),
|
|
|
- }, deleteOptions.middlewares...)
|
|
|
+ }, deleteMiddlewares...)
|
|
|
} else {
|
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/delete",
|
|
|
@@ -88,12 +92,14 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.DeleteQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: DeleteTx(tableName, deleteOptions.callbacks),
|
|
|
- }, deleteOptions.middlewares...)
|
|
|
+ }, deleteMiddlewares...)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 修改
|
|
|
if !updateOptions.disable {
|
|
|
+ updateMiddlewares := append(middlewares, updateOptions.middlewares...)
|
|
|
+
|
|
|
if !updateOptions.needTx {
|
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/update",
|
|
|
@@ -101,7 +107,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.UpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: Update(tableName, updateOptions.callbacks),
|
|
|
- }, updateOptions.middlewares...)
|
|
|
+ }, updateMiddlewares...)
|
|
|
} else {
|
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
|
Path: domainPath + "/update",
|
|
|
@@ -109,30 +115,34 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.UpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: UpdateTx(tableName, updateOptions.callbacks),
|
|
|
- }, updateOptions.middlewares...)
|
|
|
+ }, updateMiddlewares...)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 查询
|
|
|
if !queryOptions.disable {
|
|
|
+ queryMiddlewares := append(middlewares, queryOptions.middlewares...)
|
|
|
+
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
|
Path: domainPath + "/query",
|
|
|
SendResponseFunc: response.SendInfosResponse[I],
|
|
|
RequestParams: simple.QueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: Query[I](tableName, queryOptions.callbacks, queryOptions.conditionFieldCallback),
|
|
|
- }, queryOptions.middlewares...)
|
|
|
+ }, queryMiddlewares...)
|
|
|
}
|
|
|
|
|
|
// 通过ID获取
|
|
|
if !getByIDOptions.disable {
|
|
|
+ getByIDMiddlewares := append(middlewares, getByIDOptions.middlewares...)
|
|
|
+
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[I]{
|
|
|
Path: domainPath + "/get",
|
|
|
SendResponseFunc: response.SendInfoResponse[I],
|
|
|
RequestParams: simple.GetByIDQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
ServiceFunc: GetByID[I](tableName, getByIDOptions.callbacks),
|
|
|
- }, getByIDOptions.middlewares...)
|
|
|
+ }, getByIDMiddlewares...)
|
|
|
}
|
|
|
}
|
|
|
|