yjp před 1 rokem
rodič
revize
11803e356a

+ 10 - 10
convenient/relation/one2one/simple.go

@@ -35,20 +35,20 @@ type Simple[LI any, RI any] struct {
 	// 更新左实体关联使用的请求参数
 	LeftUpdateJsonBody request.WithID
 
-	// 查询左实体关联使用的请求参数,注意是Query类型
-	LeftQueryQueryParams request.QueryWithID
+	// 查询左实体关联使用的请求参数,注意是WithID类型
+	LeftQueryQueryParams request.WithID
 
-	// 更新右实体关联使用的请求参数
-	RightUpdateJsonBody request.WithID
+	// 查询左实体带右实体信息使用的请求参数,注意是WithID类型
+	LeftQueryWithRightQueryParams request.WithID
 
-	// 查询右实体关联使用的请求参数,注意是Query类型
-	RightQueryQueryParams request.QueryWithID
+	// 更新右实体关联使用的请求参数,注意是WithID类型
+	RightUpdateJsonBody request.WithID
 
-	// 查询左实体带右实体信息使用的请求参数,注意是Query类型
-	LeftQueryWithRightQueryParams request.QueryWithID
+	// 查询右实体关联使用的请求参数,注意是WithID类型
+	RightQueryQueryParams request.WithID
 
-	// 查询右实体带左实体信息使用的请求参数,注意是Query类型
-	RightQueryWithLeftQueryParams request.QueryWithID
+	// 查询右实体带左实体信息使用的请求参数,注意是WithID类型
+	RightQueryWithLeftQueryParams request.WithID
 
 	// 可选配置项,通过WithXXX配置
 	options *Options

+ 1 - 0
examples/examples/project/application/application.go

@@ -39,6 +39,7 @@ var applications = []Service{
 	&service.Class{},
 	&service.Student{},
 	&service.Family{},
+	&service.StudentAndFamily{},
 }
 
 func Start() error {

+ 4 - 0
examples/examples/project/application/domain/class/entity.go

@@ -10,6 +10,10 @@ const (
 	TableName = "test.classes"
 )
 
+const (
+	DomainPath = "/class"
+)
+
 const (
 	ColumnName       = "name"
 	ColumnStudentNum = "student_num"

+ 4 - 0
examples/examples/project/application/domain/family/entity.go

@@ -10,6 +10,10 @@ const (
 	TableName = "test.families"
 )
 
+const (
+	DomainPath = "/family"
+)
+
 const (
 	ColumnFather = "father"
 	ColumnMother = "mother"

+ 13 - 0
examples/examples/project/application/domain/family/request_params.go

@@ -29,4 +29,17 @@ type (
 	GetByIDQueryParams struct {
 		request.IDQuery
 	}
+
+	UpdateStudentOfFamilyJsonBody struct {
+		request.IDJsonBody
+		StudentID string `json:"studentId" binding:"required" assign:"toField:StudentID"`
+	}
+
+	QueryStudentOfFamilyQueryParams struct {
+		request.IDQuery
+	}
+
+	QueryFamilyWithStudentQueryParams struct {
+		request.IDQuery
+	}
 )

+ 4 - 0
examples/examples/project/application/domain/student/entity.go

@@ -10,6 +10,10 @@ const (
 	TableName = "test.students"
 )
 
+const (
+	DomainPath = "/student"
+)
+
 const (
 	ColumnName = "name"
 )

+ 13 - 0
examples/examples/project/application/domain/student/request_params.go

@@ -26,4 +26,17 @@ type (
 	GetByIDQueryParams struct {
 		request.IDQuery
 	}
+
+	UpdateFamilyOfStudentJsonBody struct {
+		request.IDJsonBody
+		FamilyID string `json:"familyId" binding:"required" assign:"toField:FamilyID"`
+	}
+
+	QueryFamilyOfStudentQueryParams struct {
+		request.IDQuery
+	}
+
+	QueryStudentWithFamilyQueryParams struct {
+		request.IDQuery
+	}
 )

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

@@ -23,7 +23,7 @@ func (app *Class) v1(appInstance *application.App) {
 	entity.BindSimple[class.Info](v1Binder, &entity.Simple[class.Info]{
 		Entity:             &class.Entity{},
 		TableName:          class.TableName,
-		DomainPath:         "/class",
+		DomainPath:         class.DomainPath,
 		CreateJsonBody:     &class.CreateJsonBody{},
 		DeleteQueryParams:  &class.DeletePathParams{},
 		UpdateJsonBody:     &class.UpdateJsonBody{},

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

@@ -23,7 +23,7 @@ func (app *Family) v1(appInstance *application.App) {
 	entity.BindSimple[family.Info](v1Binder, &entity.Simple[family.Info]{
 		Entity:             &family.Entity{},
 		TableName:          family.TableName,
-		DomainPath:         "/family",
+		DomainPath:         family.DomainPath,
 		CreateJsonBody:     &family.CreateJsonBody{},
 		DeleteQueryParams:  &family.DeletePathParams{},
 		UpdateJsonBody:     &family.UpdateJsonBody{},

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

@@ -23,7 +23,7 @@ func (app *Student) v1(appInstance *application.App) {
 	entity.BindSimple[student.Info](v1Binder, &entity.Simple[student.Info]{
 		Entity:             &student.Entity{},
 		TableName:          student.TableName,
-		DomainPath:         "/student",
+		DomainPath:         student.DomainPath,
 		CreateJsonBody:     &student.CreateJsonBody{},
 		DeleteQueryParams:  &student.DeletePathParams{},
 		UpdateJsonBody:     &student.UpdateJsonBody{},

+ 38 - 0
examples/examples/project/application/service/student_and_family.go

@@ -0,0 +1,38 @@
+package service
+
+import (
+	"git.sxidc.com/go-framework/baize/convenient/relation/one2one"
+	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/family"
+	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/student"
+	"git.sxidc.com/go-framework/baize/framwork/application"
+)
+
+type StudentAndFamily struct{}
+
+func (app *StudentAndFamily) Init(appInstance *application.App) error {
+	app.v1(appInstance)
+	return nil
+}
+
+func (app *StudentAndFamily) Destroy() error {
+	return nil
+}
+
+func (app *StudentAndFamily) v1(appInstance *application.App) {
+	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+
+	one2one.BindSimple(v1Binder, &one2one.Simple[student.Info, family.Info]{
+		Left:                          &student.Entity{},
+		Right:                         &family.Entity{},
+		LeftTableName:                 student.TableName,
+		RightTableName:                family.TableName,
+		LeftDomainPath:                student.DomainPath,
+		RightDomainPath:               family.DomainPath,
+		LeftUpdateJsonBody:            &student.UpdateFamilyOfStudentJsonBody{},
+		LeftQueryQueryParams:          &student.QueryFamilyOfStudentQueryParams{},
+		LeftQueryWithRightQueryParams: &student.QueryStudentWithFamilyQueryParams{},
+		RightUpdateJsonBody:           &family.UpdateStudentOfFamilyJsonBody{},
+		RightQueryQueryParams:         &family.QueryStudentOfFamilyQueryParams{},
+		RightQueryWithLeftQueryParams: &family.QueryFamilyWithStudentQueryParams{},
+	})
+}

+ 8 - 0
examples/examples/project/main.go

@@ -35,6 +35,14 @@ import (
 // curl -X GET "http://localhost:31000/example/v1/family/get?id=8a3af91da12c4a3eb040ffb535693f1a"
 // curl -X DELETE "http://localhost:31000/example/v1/family/8a3af91da12c4a3eb040ffb535693f1a/delete"
 
+// Student-Family
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"fc3e96926aac46268ae783c4ad675d43", "familyId": "ed86bbb59a80429eb654d7f9f13ff116"}' "http://localhost:31000/example/v1/student/family/update"
+// curl -X GET "http://localhost:31000/example/v1/example/v1/student/family/query?id="
+
+// Family-Student
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"ed86bbb59a80429eb654d7f9f13ff116", "studentId": "fc3e96926aac46268ae783c4ad675d43"}' "http://localhost:31000/example/v1/family/student/update"
+// curl -X GET "http://localhost:31000/example/v1/example/v1/family/student/query?id="
+
 func main() {
 	application.NewApp()
 	defer application.DestroyApp()