yjp 1 vuosi sitten
vanhempi
commit
3380ea5ffd

+ 9 - 9
convenient/relation/remote/simple.go

@@ -12,7 +12,7 @@ import (
 
 // Simple 关联的Bind参数
 // I 为本地实体的Info类型
-type Simple[I any] struct {
+type Simple[LI any, RI any] struct {
 	// 左领域实体,注意是Entity类型
 	Left entity.Entity
 
@@ -44,7 +44,7 @@ type Simple[I any] struct {
 	options *Options
 }
 
-func (simple *Simple[I]) bind(binder *binding.Binder) {
+func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
 	options := simple.options
 
 	leftDomainPath := domain.RelativeDomainPath(simple.Left)
@@ -84,12 +84,12 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 					ServiceFunc:   QueryToRemote(middleTableName, simple.LeftRemote, leftTableName, leftRelationColumnName, rightRelationColumnName),
 				})
 			} else {
-				binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
+				binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[RI]]{
 					Path:          leftDomainPath + rightDomainPath + "/query",
-					ResponseFunc:  response.SendInfosResponse[I],
+					ResponseFunc:  response.SendInfosResponse[RI],
 					RequestParams: simple.LeftQueryQueryParams,
 					Objects:       []domain.Object{simple.Left},
-					ServiceFunc: QueryToExist[I](middleTableName,
+					ServiceFunc: QueryToExist[RI](middleTableName,
 						simple.LeftRemote, leftTableName, leftRelationColumnName,
 						rightTableName, rightRelationColumnName),
 				})
@@ -122,12 +122,12 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 					ServiceFunc:   QueryToRemote(middleTableName, simple.RightRemote, rightTableName, rightRelationColumnName, leftRelationColumnName),
 				})
 			} else {
-				binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
+				binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[LI]]{
 					Path:          rightDomainPath + leftDomainPath + "/query",
-					ResponseFunc:  response.SendInfosResponse[I],
+					ResponseFunc:  response.SendInfosResponse[LI],
 					RequestParams: simple.RightQueryQueryParams,
 					Objects:       []domain.Object{simple.Right},
-					ServiceFunc: QueryToExist[I](middleTableName,
+					ServiceFunc: QueryToExist[LI](middleTableName,
 						simple.RightRemote, rightTableName, rightRelationColumnName,
 						leftTableName, leftRelationColumnName),
 				})
@@ -136,7 +136,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 	}
 }
 
-func BindSimple[I any](binder *binding.Binder, simple *Simple[I], opts ...Option) {
+func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option) {
 	options := new(Options)
 
 	for _, opt := range opts {

+ 1 - 1
examples/examples/project/application/service/student_and_hobby.go

@@ -21,7 +21,7 @@ func (svc *StudentAndHobbyService) Destroy() error {
 func (svc *StudentAndHobbyService) v1(appInstance *application.App) {
 	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
 
-	remote.BindSimple(v1Binder, &remote.Simple[student.Info]{
+	remote.BindSimple(v1Binder, &remote.Simple[student.Info, string]{
 		Left:                  &student.Entity{},
 		Right:                 &hobby.Entity{},
 		LeftRemote:            false,