|
@@ -20,6 +20,9 @@ type Simple[LI any, RI any] struct {
|
|
|
// 右领域实体,注意是Entity类型
|
|
// 右领域实体,注意是Entity类型
|
|
|
Right entity.Entity
|
|
Right entity.Entity
|
|
|
|
|
|
|
|
|
|
+ // 数据库schema
|
|
|
|
|
+ Schema string
|
|
|
|
|
+
|
|
|
// 更新左实体关联使用的请求参数
|
|
// 更新左实体关联使用的请求参数
|
|
|
LeftUpdateJsonBody request.Params
|
|
LeftUpdateJsonBody request.Params
|
|
|
|
|
|
|
@@ -46,9 +49,9 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
rightRelationFieldName := fmt.Sprintf("%sIDs", simple.Left.DomainCamelName())
|
|
rightRelationFieldName := fmt.Sprintf("%sIDs", simple.Left.DomainCamelName())
|
|
|
|
|
|
|
|
middleTableName := entity.SnakeDomainName(simple.Left) + "_and_" + entity.SnakeDomainName(simple.Right)
|
|
middleTableName := entity.SnakeDomainName(simple.Left) + "_and_" + entity.SnakeDomainName(simple.Right)
|
|
|
- leftTableName := entity.TableName(simple.Left)
|
|
|
|
|
|
|
+ leftTableName := entity.TableName(simple.Schema, simple.Left)
|
|
|
leftRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(simple.Right.DomainCamelName()))
|
|
leftRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(simple.Right.DomainCamelName()))
|
|
|
- rightTableName := entity.TableName(simple.Right)
|
|
|
|
|
|
|
+ rightTableName := entity.TableName(simple.Schema, simple.Right)
|
|
|
rightRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(simple.Left.DomainCamelName()))
|
|
rightRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(simple.Left.DomainCamelName()))
|
|
|
|
|
|
|
|
if !options.disableLeft {
|
|
if !options.disableLeft {
|
|
@@ -59,18 +62,22 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.LeftUpdateJsonBody,
|
|
RequestParams: simple.LeftUpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
Objects: []domain.Object{simple.Left},
|
|
|
- ServiceFunc: Update(),
|
|
|
|
|
|
|
+ ServiceFunc: Update(middleTableName,
|
|
|
|
|
+ leftTableName, simple.Left.DomainCNName(), leftRelationFieldName, leftRelationColumnName,
|
|
|
|
|
+ rightTableName, rightRelationColumnName),
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if !options.disableLeftQuery {
|
|
if !options.disableLeftQuery {
|
|
|
// 左到右查询
|
|
// 左到右查询
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[RI]{
|
|
|
|
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[RI]]{
|
|
|
Path: leftDomainPath + rightDomainPath + "/query",
|
|
Path: leftDomainPath + rightDomainPath + "/query",
|
|
|
- ResponseFunc: response.SendInfoResponse[RI],
|
|
|
|
|
|
|
+ ResponseFunc: response.SendInfosResponse[RI],
|
|
|
RequestParams: simple.LeftQueryQueryParams,
|
|
RequestParams: simple.LeftQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
Objects: []domain.Object{simple.Left},
|
|
|
- ServiceFunc: Query[RI](),
|
|
|
|
|
|
|
+ ServiceFunc: Query[RI](middleTableName,
|
|
|
|
|
+ leftTableName, leftRelationColumnName,
|
|
|
|
|
+ rightTableName, rightRelationColumnName),
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -83,18 +90,22 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
RequestParams: simple.RightUpdateJsonBody,
|
|
RequestParams: simple.RightUpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
Objects: []domain.Object{simple.Right},
|
|
|
- ServiceFunc: Update(),
|
|
|
|
|
|
|
+ ServiceFunc: Update(middleTableName,
|
|
|
|
|
+ rightTableName, simple.Right.DomainCNName(), rightRelationFieldName, rightRelationColumnName,
|
|
|
|
|
+ leftTableName, leftRelationColumnName),
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if !options.disableRightQuery {
|
|
if !options.disableRightQuery {
|
|
|
// 右到左查询
|
|
// 右到左查询
|
|
|
- binding.GetBind(binder, &binding.SimpleBindItem[RI]{
|
|
|
|
|
|
|
+ binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[LI]]{
|
|
|
Path: rightDomainPath + leftDomainPath + "/query",
|
|
Path: rightDomainPath + leftDomainPath + "/query",
|
|
|
- ResponseFunc: response.SendInfoResponse[RI],
|
|
|
|
|
|
|
+ ResponseFunc: response.SendInfosResponse[LI],
|
|
|
RequestParams: simple.RightQueryQueryParams,
|
|
RequestParams: simple.RightQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
Objects: []domain.Object{simple.Right},
|
|
|
- ServiceFunc: Query[RI](),
|
|
|
|
|
|
|
+ ServiceFunc: Query[LI](middleTableName,
|
|
|
|
|
+ rightTableName, rightRelationColumnName,
|
|
|
|
|
+ leftTableName, leftRelationColumnName),
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|