yjp hai 1 ano
pai
achega
599014574a

+ 2 - 6
convenient/binding/bind_item.go

@@ -88,18 +88,14 @@ func (item *BindItem[O]) bind(binder *Binder, middlewares ...api.Handler) {
 							item.ResponseFunc(c, http.StatusBadRequest, outputZero, err)
 							return
 						}
+					case http.MethodDelete:
+						fallthrough
 					case http.MethodGet:
 						err := request.QueryParams(c, params)
 						if err != nil {
 							item.ResponseFunc(c, http.StatusBadRequest, outputZero, err)
 							return
 						}
-					case http.MethodDelete:
-						err := request.PathParams(c, params)
-						if err != nil {
-							item.ResponseFunc(c, http.StatusBadRequest, outputZero, err)
-							return
-						}
 					}
 				}
 			}

+ 2 - 1
convenient/binding/simple_bind_item.go

@@ -41,8 +41,9 @@ type SimpleBindItem[O any] struct {
 	RequestParams request.Params
 
 	// 可选的请求参数绑定函数
-	// 非必传,POST和PUT请求默认为JsonBody,DELETE默认为PathParams,GET默认为QueryParams
+	// 非必传,POST和PUT请求默认为JsonBody,DELETEGET默认为QueryParams
 	// 额外还提供了一些转化函数:
+	// PathParams: 绑定路径参数
 	// MultipartForm: 绑定multipart form
 	// FormBody: 绑定form body
 	// XMLBody: 绑定XML body

+ 4 - 4
convenient/domain/configuration/api.go

@@ -38,10 +38,10 @@ func (simple *Simple) bind(binder *binding.Binder) {
 	}
 
 	value_object.BindSimple(binder, &value_object.Simple[any]{
-		ValueObject:       &Entity{},
-		Schema:            simple.Schema,
-		CreateJsonBody:    &AddConfigurationJsonBody{},
-		DeleteQueryParams: &RemoveConfigurationJsonBody{},
+		ValueObject:    &Entity{},
+		Schema:         simple.Schema,
+		CreateJsonBody: &AddConfigurationJsonBody{},
+		DeleteJsonBody: &RemoveConfigurationJsonBody{},
 	}, valueObjectOptions...)
 
 	if !options.disableQuery {

+ 2 - 2
convenient/entity/simple.go

@@ -68,7 +68,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 	if !options.disableDelete {
 		if !options.deleteNeedTx {
 			binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
-				Path:          domainPath + "/:id/delete",
+				Path:          domainPath + "/delete",
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.DeleteQueryParams,
 				Objects:       []domain.Object{simple.Entity},
@@ -76,7 +76,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 			}, options.deleteMiddlewares...)
 		} else {
 			binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
-				Path:          domainPath + "/:id/delete",
+				Path:          domainPath + "/delete",
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.DeleteQueryParams,
 				Objects:       []domain.Object{simple.Entity},

+ 4 - 4
convenient/value_object/simple.go

@@ -21,8 +21,8 @@ type Simple[I any] struct {
 	// 创建使用的请求参数
 	CreateJsonBody request.Params
 
-	// 删除使用的请求参数,注意是WithID类型
-	DeleteQueryParams request.Params
+	// 删除使用的请求参数
+	DeleteJsonBody request.Params
 
 	// 查询使用的请求参数,注意是Query类型
 	QueryQueryParams request.QueryRequestParams
@@ -64,7 +64,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 			binding.PostBind(binder, &binding.SimpleBindItem[any]{
 				Path:                  domainPath + "/delete",
 				ResponseFunc:          response.SendMsgResponse,
-				RequestParams:         simple.DeleteQueryParams,
+				RequestParams:         simple.DeleteJsonBody,
 				RequestParamsBindFunc: request.JsonBody,
 				Objects:               []domain.Object{simple.ValueObject},
 				ServiceFunc:           Delete(tableName, options.deleteCallbacks),
@@ -73,7 +73,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 			binding.PostBind(binder, &binding.SimpleBindItem[any]{
 				Path:                  domainPath + "/delete",
 				ResponseFunc:          response.SendMsgResponse,
-				RequestParams:         simple.DeleteQueryParams,
+				RequestParams:         simple.DeleteJsonBody,
 				RequestParamsBindFunc: request.JsonBody,
 				Objects:               []domain.Object{simple.ValueObject},
 				ServiceFunc:           DeleteTx(tableName, options.deleteCallbacks),

+ 2 - 2
examples/examples/project/application/domain/class/request_params.go

@@ -10,8 +10,8 @@ type (
 		StudentNum int    `json:"studentNum" binding:"required" assign:"toField:StudentNum"`
 	}
 
-	DeletePathParams struct {
-		request.IDPathParam
+	DeleteQueryParams struct {
+		request.IDQueryParam
 	}
 
 	UpdateJsonBody struct {

+ 2 - 2
examples/examples/project/application/domain/family/request_params.go

@@ -10,8 +10,8 @@ type (
 		Mother string `json:"mother" binding:"required" assign:"toField:Mother"`
 	}
 
-	DeletePathParams struct {
-		request.IDPathParam
+	DeleteQueryParams struct {
+		request.IDQueryParam
 	}
 
 	UpdateJsonBody struct {

+ 2 - 2
examples/examples/project/application/domain/identity/request_params.go

@@ -9,8 +9,8 @@ type (
 		Name string `json:"name" binding:"required" assign:"toField:Name"`
 	}
 
-	DeletePathParams struct {
-		request.IDPathParam
+	DeleteQueryParams struct {
+		request.IDQueryParam
 	}
 
 	UpdateJsonBody struct {

+ 2 - 2
examples/examples/project/application/domain/student/request_params.go

@@ -9,8 +9,8 @@ type (
 		Name string `json:"name" binding:"required" assign:"toField:Name"`
 	}
 
-	DeletePathParams struct {
-		request.IDPathParam
+	DeleteQueryParams struct {
+		request.IDQueryParam
 	}
 
 	UpdateJsonBody struct {

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

@@ -24,7 +24,7 @@ func (app *Class) v1(appInstance *application.App) {
 		Entity:             &class.Entity{},
 		Schema:             dbSchema,
 		CreateJsonBody:     &class.CreateJsonBody{},
-		DeleteQueryParams:  &class.DeletePathParams{},
+		DeleteQueryParams:  &class.DeleteQueryParams{},
 		UpdateJsonBody:     &class.UpdateJsonBody{},
 		QueryQueryParams:   &class.QueryQueryParams{},
 		GetByIDQueryParams: &class.GetByIDQueryParams{},

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

@@ -24,7 +24,7 @@ func (app *Family) v1(appInstance *application.App) {
 		Entity:             &family.Entity{},
 		Schema:             dbSchema,
 		CreateJsonBody:     &family.CreateJsonBody{},
-		DeleteQueryParams:  &family.DeletePathParams{},
+		DeleteQueryParams:  &family.DeleteQueryParams{},
 		UpdateJsonBody:     &family.UpdateJsonBody{},
 		QueryQueryParams:   &family.QueryQueryParams{},
 		GetByIDQueryParams: &family.GetByIDQueryParams{},

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

@@ -24,7 +24,7 @@ func (app *Identity) v1(appInstance *application.App) {
 		Entity:             &identity.Entity{},
 		Schema:             dbSchema,
 		CreateJsonBody:     &identity.CreateJsonBody{},
-		DeleteQueryParams:  &identity.DeletePathParams{},
+		DeleteQueryParams:  &identity.DeleteQueryParams{},
 		UpdateJsonBody:     &identity.UpdateJsonBody{},
 		QueryQueryParams:   &identity.QueryQueryParams{},
 		GetByIDQueryParams: &identity.GetByIDQueryParams{},

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

@@ -24,7 +24,7 @@ func (app *Student) v1(appInstance *application.App) {
 		Entity:             &student.Entity{},
 		Schema:             dbSchema,
 		CreateJsonBody:     &student.CreateJsonBody{},
-		DeleteQueryParams:  &student.DeletePathParams{},
+		DeleteQueryParams:  &student.DeleteQueryParams{},
 		UpdateJsonBody:     &student.UpdateJsonBody{},
 		QueryQueryParams:   &student.QueryQueryParams{},
 		GetByIDQueryParams: &student.GetByIDQueryParams{},

+ 43 - 43
examples/examples/project/main.go

@@ -7,75 +7,75 @@ import (
 )
 
 // Version
-// curl -X GET "http://localhost:31000/example/version"
+// curl -X GET "http://localhost:31000/example/api/version"
 
 // Configuration
-// curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test", "value":"test-value"}' "http://localhost:31000/example/configuration/create"
-// curl -X GET "http://localhost:31000/example/configuration/values?scope=global&group=test&pageNo=1&pageSize=1"
-// curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test"}' "http://localhost:31000/example/configuration/delete"
+// curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test", "value":"test-value"}' "http://localhost:31000/example/api/configuration/create"
+// curl -X GET "http://localhost:31000/example/api/configuration/values?scope=global&group=test&pageNo=1&pageSize=1"
+// curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test"}' "http://localhost:31000/example/api/configuration/delete"
 
 // Class
-// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:31000/example/v1/class/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"e4a3d4474e4e4469b54bf9d41e649bf4", "name":"test-new"}' "http://localhost:31000/example/v1/class/update"
-// curl -X GET "http://localhost:31000/example/v1/class/query?name=test-new&pageNo=1&pageSize=1"
-// curl -X GET "http://localhost:31000/example/v1/class/get?id=e4a3d4474e4e4469b54bf9d41e649bf4"
-// curl -X DELETE "http://localhost:31000/example/v1/class/e4a3d4474e4e4469b54bf9d41e649bf4/delete"
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:31000/example/api/v1/class/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"4fd8dd01be48421fba65eff6360111b9", "name":"test-new"}' "http://localhost:31000/example/api/v1/class/update"
+// curl -X GET "http://localhost:31000/example/api/v1/class/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:31000/example/api/v1/class/get?id=4fd8dd01be48421fba65eff6360111b9"
+// curl -X DELETE "http://localhost:31000/example/api/v1/class/delete?id=4fd8dd01be48421fba65eff6360111b9"
 
 // Student
-// curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:31000/example/v1/student/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"fbee72deb9634497847620881eed995e", "name":"test-new"}' "http://localhost:31000/example/v1/student/update"
-// curl -X GET "http://localhost:31000/example/v1/student/query?name=test-new&pageNo=1&pageSize=1"
-// curl -X GET "http://localhost:31000/example/v1/student/get?id=fbee72deb9634497847620881eed995e"
-// curl -X DELETE "http://localhost:31000/example/v1/student/fbee72deb9634497847620881eed995e/delete"
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:31000/example/api/v1/student/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"d9332801b46c4f0c99fdd381954313d6", "name":"test-new"}' "http://localhost:31000/example/api/v1/student/update"
+// curl -X GET "http://localhost:31000/example/api/v1/student/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:31000/example/api/v1/student/get?id=d9332801b46c4f0c99fdd381954313d6"
+// curl -X DELETE "http://localhost:31000/example/api/v1/student/delete?id=d9332801b46c4f0c99fdd381954313d6"
 
 // Family
-// curl -X POST -H "Content-Type: application/json" -d '{"father":"father", "mother": "mother"}' "http://localhost:31000/example/v1/family/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"85ffbfbef27b42879382b47718c7a99e", "father":"new-father", "mother": "new-mother"}' "http://localhost:31000/example/v1/family/update"
-// curl -X GET "http://localhost:31000/example/v1/family/query?father=new-father&pageNo=0&pageSize=0"
-// curl -X GET "http://localhost:31000/example/v1/family/get?id=85ffbfbef27b42879382b47718c7a99e"
-// curl -X DELETE "http://localhost:31000/example/v1/family/85ffbfbef27b42879382b47718c7a99e/delete"
+// curl -X POST -H "Content-Type: application/json" -d '{"father":"father", "mother": "mother"}' "http://localhost:31000/example/api/v1/family/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"85ffbfbef27b42879382b47718c7a99e", "father":"new-father", "mother": "new-mother"}' "http://localhost:31000/example/api/v1/family/update"
+// curl -X GET "http://localhost:31000/example/api/v1/family/query?father=new-father&pageNo=0&pageSize=0"
+// curl -X GET "http://localhost:31000/example/api/v1/family/get?id=85ffbfbef27b42879382b47718c7a99e"
+// curl -X DELETE "http://localhost:31000/example/api/v1/family/delete?id=85ffbfbef27b42879382b47718c7a99e"
 
 // Identity
-// curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:31000/example/v1/identity/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"6e12ee71397746b8920fa94e5f229366", "name":"test-new"}' "http://localhost:31000/example/v1/identity/update"
-// curl -X GET "http://localhost:31000/example/v1/identity/query?name=test-new&pageNo=1&pageSize=1"
-// curl -X GET "http://localhost:31000/example/v1/identity/get?id=6e12ee71397746b8920fa94e5f229366"
-// curl -X DELETE "http://localhost:31000/example/v1/identity/6e12ee71397746b8920fa94e5f229366/delete"
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:31000/example/api/v1/identity/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"6e12ee71397746b8920fa94e5f229366", "name":"test-new"}' "http://localhost:31000/example/api/v1/identity/update"
+// curl -X GET "http://localhost:31000/example/api/v1/identity/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:31000/example/api/v1/identity/get?id=6e12ee71397746b8920fa94e5f229366"
+// curl -X DELETE "http://localhost:31000/example/api/v1/identity/delete?id=6e12ee71397746b8920fa94e5f229366"
 
 // Class-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"a38786c698904224a6fc36a23c2eec1e", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/v1/class/student/update"
-// curl -X GET "http://localhost:31000/example/v1/class/student/query?id=a38786c698904224a6fc36a23c2eec1e"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"a38786c698904224a6fc36a23c2eec1e", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/api/v1/class/student/update"
+// curl -X GET "http://localhost:31000/example/api/v1/class/student/query?id=a38786c698904224a6fc36a23c2eec1e"
 
 // Student-Class
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "classId": "a38786c698904224a6fc36a23c2eec1e"}' "http://localhost:31000/example/v1/student/class/update"
-// curl -X GET "http://localhost:31000/example/v1/student/class/query?id=00254b4a7102429db35e6edc8e47a764"
-// curl -X GET "http://localhost:31000/example/v1/student/class/queryWith?name=test"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "classId": "a38786c698904224a6fc36a23c2eec1e"}' "http://localhost:31000/example/api/v1/student/class/update"
+// curl -X GET "http://localhost:31000/example/api/v1/student/class/query?id=00254b4a7102429db35e6edc8e47a764"
+// curl -X GET "http://localhost:31000/example/api/v1/student/class/queryWith?name=test"
 
 // Student-Family
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "familyId": "df3aeee04ce94c17878bbb5383d15f18"}' "http://localhost:31000/example/v1/student/family/update"
-// curl -X GET "http://localhost:31000/example/v1/student/family/query?id=00254b4a7102429db35e6edc8e47a764"
-// curl -X GET "http://localhost:31000/example/v1/student/family/queryWith?father=test"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "familyId": "df3aeee04ce94c17878bbb5383d15f18"}' "http://localhost:31000/example/api/v1/student/family/update"
+// curl -X GET "http://localhost:31000/example/api/v1/student/family/query?id=00254b4a7102429db35e6edc8e47a764"
+// curl -X GET "http://localhost:31000/example/api/v1/student/family/queryWith?father=test"
 
 // Family-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"df3aeee04ce94c17878bbb5383d15f18", "studentId": "00254b4a7102429db35e6edc8e47a764"}' "http://localhost:31000/example/v1/family/student/update"
-// curl -X GET "http://localhost:31000/example/v1/family/student/query?id=df3aeee04ce94c17878bbb5383d15f18"
-// curl -X GET "http://localhost:31000/example/v1/family/student/queryWith?father=test"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"df3aeee04ce94c17878bbb5383d15f18", "studentId": "00254b4a7102429db35e6edc8e47a764"}' "http://localhost:31000/example/api/v1/family/student/update"
+// curl -X GET "http://localhost:31000/example/api/v1/family/student/query?id=df3aeee04ce94c17878bbb5383d15f18"
+// curl -X GET "http://localhost:31000/example/api/v1/family/student/queryWith?father=test"
 
 // Student-Identity
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "identityIds": ["4481fd110a5f46d2babe52b650981384"]}' "http://localhost:31000/example/v1/student/identity/update"
-// curl -X GET "http://localhost:31000/example/v1/student/identity/query?id=00254b4a7102429db35e6edc8e47a764"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "identityIds": ["4481fd110a5f46d2babe52b650981384"]}' "http://localhost:31000/example/api/v1/student/identity/update"
+// curl -X GET "http://localhost:31000/example/api/v1/student/identity/query?id=00254b4a7102429db35e6edc8e47a764"
 
 // Identity-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"4481fd110a5f46d2babe52b650981384", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/v1/identity/student/update"
-// curl -X GET "http://localhost:31000/example/v1/identity/student/query?id=4481fd110a5f46d2babe52b650981384"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"4481fd110a5f46d2babe52b650981384", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/api/v1/identity/student/update"
+// curl -X GET "http://localhost:31000/example/api/v1/identity/student/query?id=4481fd110a5f46d2babe52b650981384"
 
 // Student-Hobby
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "hobbyIds": ["42b305bb292c4082a3e91a2967f11111"]}' "http://localhost:31000/example/v1/student/hobby/update"
-// curl -X GET "http://localhost:31000/example/v1/student/hobby/query?id=00254b4a7102429db35e6edc8e47a764"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"00254b4a7102429db35e6edc8e47a764", "hobbyIds": ["42b305bb292c4082a3e91a2967f11111"]}' "http://localhost:31000/example/api/v1/student/hobby/update"
+// curl -X GET "http://localhost:31000/example/api/v1/student/hobby/query?id=00254b4a7102429db35e6edc8e47a764"
 
 // Hobby-Student
-// curl -X POST -H "Content-Type: application/json" -d '{"id":"42b305bb292c4082a3e91a2967f11111", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/v1/hobby/student/update"
-// curl -X GET "http://localhost:31000/example/v1/hobby/student/query?id=42b305bb292c4082a3e91a2967f11111"
+// curl -X POST -H "Content-Type: application/json" -d '{"id":"42b305bb292c4082a3e91a2967f11111", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/api/v1/hobby/student/update"
+// curl -X GET "http://localhost:31000/example/api/v1/hobby/student/query?id=42b305bb292c4082a3e91a2967f11111"
 
 func main() {
 	application.NewApp()