|
|
@@ -28,15 +28,6 @@ type Simple[I any] struct {
|
|
|
// 数据库Schema
|
|
|
Schema string
|
|
|
|
|
|
- // 中间表表名
|
|
|
- MiddleTableName string
|
|
|
-
|
|
|
- // URL领域相对路径,如/person,后面会自动补充,如/person/右领域path/update
|
|
|
- LeftDomainPath string
|
|
|
-
|
|
|
- // URL领域相对路径,如/identity,后面会自动补充,如/identity/左领域path/update
|
|
|
- RightDomainPath string
|
|
|
-
|
|
|
// 更新左实体关联使用的请求参数
|
|
|
LeftUpdateJsonBody request.Params
|
|
|
|
|
|
@@ -71,48 +62,36 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
if !options.disableLeft {
|
|
|
if !options.disableLeftUpdate {
|
|
|
// 左到右更新
|
|
|
- if !simple.LeftRemote {
|
|
|
- binding.PostBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: leftDomainPath + rightDomainPath + "/update",
|
|
|
- ResponseFunc: response.SendMsgResponse,
|
|
|
- RequestParams: simple.LeftUpdateJsonBody,
|
|
|
- Objects: []domain.Object{simple.Left},
|
|
|
- ServiceFunc: UpdateFromExist(middleTableName,
|
|
|
- leftTableName, simple.Left.DomainCNName(), leftRelationFieldName, leftRelationColumnName,
|
|
|
- rightTableName, rightRelationColumnName),
|
|
|
- })
|
|
|
- } else {
|
|
|
- binding.PostBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: leftDomainPath + rightDomainPath + "/update",
|
|
|
- ResponseFunc: response.SendMsgResponse,
|
|
|
- RequestParams: simple.LeftUpdateJsonBody,
|
|
|
- Objects: []domain.Object{simple.Left},
|
|
|
- ServiceFunc: UpdateFromRemote(middleTableName,
|
|
|
- simple.Left.DomainCNName(), leftRelationFieldName, leftRelationColumnName,
|
|
|
- rightTableName, rightRelationColumnName),
|
|
|
- })
|
|
|
- }
|
|
|
+ binding.PostBind(binder, &binding.SimpleBindItem[any]{
|
|
|
+ Path: leftDomainPath + rightDomainPath + "/update",
|
|
|
+ ResponseFunc: response.SendMsgResponse,
|
|
|
+ RequestParams: simple.LeftUpdateJsonBody,
|
|
|
+ Objects: []domain.Object{simple.Left},
|
|
|
+ ServiceFunc: Update(middleTableName,
|
|
|
+ simple.LeftRemote, leftTableName, simple.Left.DomainCNName(), leftRelationFieldName, leftRelationColumnName,
|
|
|
+ simple.RightRemote, rightTableName, rightRelationColumnName),
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
if !options.disableLeftQuery {
|
|
|
// 左到右查询
|
|
|
- if !simple.LeftRemote {
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
|
+ if simple.RightRemote {
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[string]]{
|
|
|
Path: leftDomainPath + rightDomainPath + "/query",
|
|
|
- ResponseFunc: response.SendInfosResponse[I],
|
|
|
+ ResponseFunc: response.SendInfosResponse[string],
|
|
|
RequestParams: simple.LeftQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
|
- ServiceFunc: QueryFromExist[I](middleTableName,
|
|
|
- leftTableName, leftRelationColumnName,
|
|
|
- rightTableName, rightRelationColumnName),
|
|
|
+ ServiceFunc: QueryToRemote(middleTableName, simple.LeftRemote, leftTableName, leftRelationColumnName, rightRelationColumnName),
|
|
|
})
|
|
|
} else {
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[string]]{
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
|
Path: leftDomainPath + rightDomainPath + "/query",
|
|
|
- ResponseFunc: response.SendInfosResponse[string],
|
|
|
+ ResponseFunc: response.SendInfosResponse[I],
|
|
|
RequestParams: simple.LeftQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
|
- ServiceFunc: QueryFromRemote(middleTableName, leftRelationColumnName, rightRelationColumnName),
|
|
|
+ ServiceFunc: QueryToExist[I](middleTableName,
|
|
|
+ simple.LeftRemote, leftTableName, leftRelationColumnName,
|
|
|
+ rightTableName, rightRelationColumnName),
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -121,55 +100,43 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
|
|
|
if !options.disableRight {
|
|
|
if !options.disableRightUpdate {
|
|
|
// 右到左更新
|
|
|
- if !simple.RightRemote {
|
|
|
- binding.PostBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: rightDomainPath + leftDomainPath + "/update",
|
|
|
- ResponseFunc: response.SendMsgResponse,
|
|
|
- RequestParams: simple.RightUpdateJsonBody,
|
|
|
- Objects: []domain.Object{simple.Right},
|
|
|
- ServiceFunc: UpdateFromExist(middleTableName,
|
|
|
- rightTableName, simple.Right.DomainCNName(), rightRelationFieldName, rightRelationColumnName,
|
|
|
- leftTableName, leftRelationColumnName),
|
|
|
- })
|
|
|
- } else {
|
|
|
- binding.PostBind(binder, &binding.SimpleBindItem[any]{
|
|
|
- Path: rightDomainPath + leftDomainPath + "/update",
|
|
|
- ResponseFunc: response.SendMsgResponse,
|
|
|
- RequestParams: simple.RightUpdateJsonBody,
|
|
|
- Objects: []domain.Object{simple.Right},
|
|
|
- ServiceFunc: UpdateFromRemote(middleTableName,
|
|
|
- simple.Right.DomainCNName(), rightRelationFieldName, rightRelationColumnName,
|
|
|
- leftTableName, leftRelationColumnName),
|
|
|
- })
|
|
|
- }
|
|
|
+ binding.PostBind(binder, &binding.SimpleBindItem[any]{
|
|
|
+ Path: rightDomainPath + leftDomainPath + "/update",
|
|
|
+ ResponseFunc: response.SendMsgResponse,
|
|
|
+ RequestParams: simple.RightUpdateJsonBody,
|
|
|
+ Objects: []domain.Object{simple.Right},
|
|
|
+ ServiceFunc: Update(middleTableName,
|
|
|
+ simple.RightRemote, rightTableName, simple.Right.DomainCNName(), rightRelationFieldName, rightRelationColumnName,
|
|
|
+ simple.LeftRemote, leftTableName, leftRelationColumnName),
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
if !options.disableRightQuery {
|
|
|
// 右到左查询
|
|
|
- if !simple.RightRemote {
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
|
+ if simple.LeftRemote {
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[string]]{
|
|
|
Path: rightDomainPath + leftDomainPath + "/query",
|
|
|
- ResponseFunc: response.SendInfosResponse[I],
|
|
|
+ ResponseFunc: response.SendInfosResponse[string],
|
|
|
RequestParams: simple.RightQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
|
- ServiceFunc: QueryFromExist[I](middleTableName,
|
|
|
- rightTableName, rightRelationColumnName,
|
|
|
- leftTableName, leftRelationColumnName),
|
|
|
+ ServiceFunc: QueryToRemote(middleTableName, simple.RightRemote, rightTableName, rightRelationColumnName, leftRelationColumnName),
|
|
|
})
|
|
|
} else {
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[string]]{
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
|
|
|
Path: rightDomainPath + leftDomainPath + "/query",
|
|
|
- ResponseFunc: response.SendInfosResponse[string],
|
|
|
+ ResponseFunc: response.SendInfosResponse[I],
|
|
|
RequestParams: simple.RightQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
|
- ServiceFunc: QueryFromRemote(middleTableName, rightRelationColumnName, leftRelationColumnName),
|
|
|
+ ServiceFunc: QueryToExist[I](middleTableName,
|
|
|
+ simple.RightRemote, rightTableName, rightRelationColumnName,
|
|
|
+ leftTableName, leftRelationColumnName),
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option) {
|
|
|
+func BindSimple[I any](binder *binding.Binder, simple *Simple[I], opts ...Option) {
|
|
|
options := new(Options)
|
|
|
|
|
|
for _, opt := range opts {
|