|
|
@@ -7,38 +7,39 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/application"
|
|
|
"git.sxidc.com/go-framework/baize/binding"
|
|
|
"git.sxidc.com/go-framework/baize/domain"
|
|
|
+ "git.sxidc.com/go-framework/baize/tag"
|
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
|
DEATH "github.com/vrecan/death"
|
|
|
"syscall"
|
|
|
)
|
|
|
|
|
|
// curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:10000/test/v1/class/create"
|
|
|
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"1fb7faa332af42fd9a41856320c0d4af", "name":"test-new"}' "http://localhost:10000/test/v1/class/update"
|
|
|
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"1b86aba688384f43a0981f1d41ac8346", "name":"test-new"}' "http://localhost:10000/test/v1/class/update"
|
|
|
// curl -X GET "http://localhost:10000/test/v1/class/query?name=test-new&pageNo=0&pageSize=1"
|
|
|
-// curl -X GET "http://localhost:10000/test/v1/class/get?id=1fb7faa332af42fd9a41856320c0d4af"
|
|
|
-// curl -X DELETE "http://localhost:10000/test/v1/class/1fb7faa332af42fd9a41856320c0d4af/delete"
|
|
|
+// curl -X GET "http://localhost:10000/test/v1/class/get?id=1b86aba688384f43a0981f1d41ac8346"
|
|
|
+// curl -X DELETE "http://localhost:10000/test/v1/class/1b86aba688384f43a0981f1d41ac8346/delete"
|
|
|
|
|
|
type CreateClassJsonBody struct {
|
|
|
- Name string `json:"name" binding:"required"`
|
|
|
+ Name string `json:"name" binding:"required" assign:"toField:Name"`
|
|
|
}
|
|
|
|
|
|
type DeleteClassPathParams struct {
|
|
|
- ID string `uri:"id" binding:"required"`
|
|
|
+ ID string `uri:"id" binding:"required" assign:"toField:ID"`
|
|
|
}
|
|
|
|
|
|
type UpdateClassJsonBody struct {
|
|
|
- ID string `json:"id" binding:"required"`
|
|
|
- Name string `json:"name"`
|
|
|
+ ID string `json:"id" binding:"required" assign:"toField:ID"`
|
|
|
+ Name string `json:"name" assign:"toField:Name"`
|
|
|
}
|
|
|
|
|
|
type QueryClassesQueryParams struct {
|
|
|
- Name string `form:"id"`
|
|
|
- PageNo int `form:"pageNo"`
|
|
|
- PageSize int `form:"pageSize"`
|
|
|
+ Name string `form:"name" assign:"toField:Name"`
|
|
|
+ PageNo int `form:"pageNo" assign:"-"`
|
|
|
+ PageSize int `form:"pageSize" assign:"-"`
|
|
|
}
|
|
|
|
|
|
type GetClassQueryParams struct {
|
|
|
- ID string `form:"id" binding:"required"`
|
|
|
+ ID string `form:"id" binding:"required" assign:"toField:ID"`
|
|
|
}
|
|
|
|
|
|
type Class struct {
|
|
|
@@ -69,12 +70,13 @@ func main() {
|
|
|
ResponseFunc: binding.SendIDResponse[string],
|
|
|
DTO: &CreateClassJsonBody{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- jsonBody := binding.ToConcreteDTO[*CreateClassJsonBody](dto)
|
|
|
- return []domain.Object{
|
|
|
- &Class{
|
|
|
- Name: jsonBody.Name,
|
|
|
- },
|
|
|
- }, nil
|
|
|
+ class := new(Class)
|
|
|
+ err := tag.AssignTo(dto, class)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return []domain.Object{class}, nil
|
|
|
},
|
|
|
ServiceFunc: func(c *api.Context, dto binding.DTO, objects []domain.Object) (string, error) {
|
|
|
e := domain.ToConcreteObject[*Class](objects[0])
|
|
|
@@ -110,10 +112,11 @@ func main() {
|
|
|
ResponseFunc: binding.SendMsgResponse,
|
|
|
DTO: &UpdateClassJsonBody{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
+ jsonBody := binding.ToConcreteDTO[*UpdateClassJsonBody](dto)
|
|
|
return []domain.Object{
|
|
|
&Class{
|
|
|
- ID: binding.Field[string](dto, "ID"),
|
|
|
- Name: binding.Field[string](dto, "Name"),
|
|
|
+ ID: jsonBody.ID,
|
|
|
+ Name: jsonBody.Name,
|
|
|
},
|
|
|
}, nil
|
|
|
},
|
|
|
@@ -143,11 +146,14 @@ func main() {
|
|
|
ResponseFunc: binding.SendInfosResponse[ClassInfo],
|
|
|
DTO: &QueryClassesQueryParams{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- return []domain.Object{
|
|
|
- &Class{
|
|
|
- Name: binding.Field[string](dto, "Name"),
|
|
|
- },
|
|
|
- }, nil
|
|
|
+ class := new(Class)
|
|
|
+ err := tag.AssignTo(dto, class)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return []domain.Object{class}, nil
|
|
|
},
|
|
|
ServiceFunc: func(c *api.Context, dto binding.DTO, objects []domain.Object) (binding.InfosData[ClassInfo], error) {
|
|
|
name := domain.Field[string](objects[0], "Name")
|
|
|
@@ -215,11 +221,13 @@ func main() {
|
|
|
ResponseFunc: binding.SendInfoResponse[*ClassInfo],
|
|
|
DTO: &GetClassQueryParams{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- return []domain.Object{
|
|
|
- &Class{
|
|
|
- ID: binding.Field[string](dto, "ID"),
|
|
|
- },
|
|
|
- }, nil
|
|
|
+ class := new(Class)
|
|
|
+ err := tag.AssignTo(dto, class)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return []domain.Object{class}, nil
|
|
|
},
|
|
|
ServiceFunc: func(c *api.Context, dto binding.DTO, objects []domain.Object) (*ClassInfo, error) {
|
|
|
id := domain.Field[string](objects[0], "ID")
|