|
|
@@ -6,19 +6,14 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/convenient/binding/response"
|
|
|
"git.sxidc.com/go-framework/baize/framwork/api"
|
|
|
"git.sxidc.com/go-framework/baize/framwork/domain"
|
|
|
+ "git.sxidc.com/go-framework/baize/framwork/domain/entity"
|
|
|
)
|
|
|
|
|
|
// Simple 实体CRUD的Bind参数
|
|
|
// I 为查询相关接口返回的Info类型
|
|
|
type Simple[I any] struct {
|
|
|
// 使用的领域实体,注意是Entity类型
|
|
|
- Entity domain.Entity
|
|
|
-
|
|
|
- // 表名
|
|
|
- TableName string
|
|
|
-
|
|
|
- // URL领域相对路径,如/class,后面会自动补充,如/class/create
|
|
|
- DomainPath string
|
|
|
+ Entity entity.Entity
|
|
|
|
|
|
// 创建使用的请求参数
|
|
|
CreateJsonBody request.Params
|
|
|
@@ -42,23 +37,26 @@ type Simple[I any] struct {
|
|
|
func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
options := simple.options
|
|
|
|
|
|
+ tableName := entity.TableName(simple.Entity)
|
|
|
+ domainPath := entity.RelativeDomainPath(simple.Entity)
|
|
|
+
|
|
|
// 创建
|
|
|
if !options.disableCreate {
|
|
|
if !options.createNeedTx {
|
|
|
binding.PostBind(binder, &binding.SimpleBindItem[string]{
|
|
|
- Path: simple.DomainPath + "/create",
|
|
|
+ Path: domainPath + "/create",
|
|
|
ResponseFunc: response.SendIDResponse[string],
|
|
|
RequestParams: simple.CreateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Create(simple.TableName, options.createCallbacks),
|
|
|
+ ServiceFunc: Create(tableName, options.createCallbacks),
|
|
|
}, options.createMiddlewares...)
|
|
|
} else {
|
|
|
binding.PostBind(binder, &binding.SimpleBindItem[string]{
|
|
|
- Path: simple.DomainPath + "/create",
|
|
|
+ Path: domainPath + "/create",
|
|
|
ResponseFunc: response.SendIDResponse[string],
|
|
|
RequestParams: simple.CreateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: CreateTx(simple.TableName, options.createCallbacks),
|
|
|
+ ServiceFunc: CreateTx(tableName, options.createCallbacks),
|
|
|
}, options.createMiddlewares...)
|
|
|
}
|
|
|
}
|
|
|
@@ -67,19 +65,19 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
if !options.disableDelete {
|
|
|
if !options.deleteNeedTx {
|
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: simple.DomainPath + "/:id/delete",
|
|
|
+ Path: domainPath + "/:id/delete",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.DeleteQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Delete(simple.TableName, options.deleteCallbacks),
|
|
|
+ ServiceFunc: Delete(tableName, options.deleteCallbacks),
|
|
|
}, options.deleteMiddlewares...)
|
|
|
} else {
|
|
|
binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: simple.DomainPath + "/:id/delete",
|
|
|
+ Path: domainPath + "/:id/delete",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.DeleteQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: DeleteTx(simple.TableName, options.deleteCallbacks),
|
|
|
+ ServiceFunc: DeleteTx(tableName, options.deleteCallbacks),
|
|
|
}, options.deleteMiddlewares...)
|
|
|
}
|
|
|
}
|
|
|
@@ -88,19 +86,19 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
if !options.disableUpdate {
|
|
|
if !options.updateNeedTx {
|
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: simple.DomainPath + "/update",
|
|
|
+ Path: domainPath + "/update",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.UpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Update(simple.TableName, options.updateCallbacks),
|
|
|
+ ServiceFunc: Update(tableName, options.updateCallbacks),
|
|
|
}, options.updateMiddlewares...)
|
|
|
} else {
|
|
|
binding.PutBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: simple.DomainPath + "/update",
|
|
|
+ Path: domainPath + "/update",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.UpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: UpdateTx(simple.TableName, options.updateCallbacks),
|
|
|
+ ServiceFunc: UpdateTx(tableName, options.updateCallbacks),
|
|
|
}, options.updateMiddlewares...)
|
|
|
}
|
|
|
}
|
|
|
@@ -108,22 +106,22 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
// 查询
|
|
|
if !options.disableQuery {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
|
- Path: simple.DomainPath + "/query",
|
|
|
+ Path: domainPath + "/query",
|
|
|
ResponseFunc: response.SendInfosResponse[I],
|
|
|
RequestParams: simple.QueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: Query[I](simple.TableName, options.queryCallbacks, options.queryConditionFieldCallback),
|
|
|
+ ServiceFunc: Query[I](tableName, options.queryCallbacks, options.queryConditionFieldCallback),
|
|
|
}, options.queryMiddlewares...)
|
|
|
}
|
|
|
|
|
|
// 通过ID获取
|
|
|
if !options.disableQueryByID {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[I]{
|
|
|
- Path: simple.DomainPath + "/get",
|
|
|
+ Path: domainPath + "/get",
|
|
|
ResponseFunc: response.SendInfoResponse[I],
|
|
|
RequestParams: simple.GetByIDQueryParams,
|
|
|
Objects: []domain.Object{simple.Entity},
|
|
|
- ServiceFunc: GetByID[I](simple.TableName, options.getByIDCallbacks),
|
|
|
+ ServiceFunc: GetByID[I](tableName, options.getByIDCallbacks),
|
|
|
}, options.getByIDMiddlewares...)
|
|
|
}
|
|
|
}
|