|
|
@@ -13,10 +13,10 @@ import (
|
|
|
)
|
|
|
|
|
|
// 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":"25a9d5dab2fc4a81a512e48d911b5063", "name":"test-new"}' "http://localhost:10000/test/v1/class/update"
|
|
|
-// curl -X GET "http://localhost:10000/test/v1/class/query?name=test&pageNo=1&pageSize=1"
|
|
|
-// curl -X GET "http://localhost:10000/test/v1/class/get?id=25a9d5dab2fc4a81a512e48d911b5063"
|
|
|
-// curl -X DELETE "http://localhost:10000/test/v1/class/25a9d5dab2fc4a81a512e48d911b5063/delete"
|
|
|
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"f630ccff4e534cb6b6b015ff21b34437", "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=f630ccff4e534cb6b6b015ff21b34437"
|
|
|
+// curl -X DELETE "http://localhost:10000/test/v1/class/f630ccff4e534cb6b6b015ff21b34437/delete"
|
|
|
|
|
|
type CreateClassJsonBody struct {
|
|
|
Name string `json:"name" binding:"required"`
|
|
|
@@ -69,14 +69,9 @@ func main() {
|
|
|
ResponseFunc: binding.SendIDResponse[string],
|
|
|
DTO: &CreateClassJsonBody{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- jsonBody, err := binding.ToConcreteDTO[*CreateClassJsonBody](dto)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
return []domain.Object{
|
|
|
&Class{
|
|
|
- Name: jsonBody.Name,
|
|
|
+ Name: binding.Field[string](dto, "Name"),
|
|
|
},
|
|
|
}, nil
|
|
|
},
|
|
|
@@ -99,14 +94,9 @@ func main() {
|
|
|
ResponseFunc: binding.SendMsgResponse,
|
|
|
DTO: &DeleteClassPathParams{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- pathParams, err := binding.ToConcreteDTO[*DeleteClassPathParams](dto)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
return []domain.Object{
|
|
|
&Class{
|
|
|
- ID: pathParams.ID,
|
|
|
+ ID: binding.Field[string](dto, "ID"),
|
|
|
},
|
|
|
}, nil
|
|
|
},
|
|
|
@@ -129,15 +119,10 @@ func main() {
|
|
|
ResponseFunc: binding.SendMsgResponse,
|
|
|
DTO: &UpdateClassJsonBody{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- jsonBody, err := binding.ToConcreteDTO[*UpdateClassJsonBody](dto)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
return []domain.Object{
|
|
|
&Class{
|
|
|
- ID: jsonBody.ID,
|
|
|
- Name: jsonBody.Name,
|
|
|
+ ID: binding.Field[string](dto, "ID"),
|
|
|
+ Name: binding.Field[string](dto, "Name"),
|
|
|
},
|
|
|
}, nil
|
|
|
},
|
|
|
@@ -170,14 +155,9 @@ func main() {
|
|
|
ResponseFunc: binding.SendInfosResponse[ClassInfo],
|
|
|
DTO: &QueryClassesQueryParams{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- queryParams, err := binding.ToConcreteDTO[*QueryClassesQueryParams](dto)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
return []domain.Object{
|
|
|
&Class{
|
|
|
- Name: queryParams.Name,
|
|
|
+ Name: binding.Field[string](dto, "Name"),
|
|
|
},
|
|
|
}, nil
|
|
|
},
|
|
|
@@ -193,23 +173,17 @@ func main() {
|
|
|
}, err
|
|
|
}
|
|
|
|
|
|
- queryParams, err := binding.ToConcreteDTO[*QueryClassesQueryParams](dto)
|
|
|
- if err != nil {
|
|
|
- return binding.InfosData[ClassInfo]{
|
|
|
- Infos: classInfos,
|
|
|
- TotalCount: 0,
|
|
|
- PageNo: 0,
|
|
|
- }, err
|
|
|
- }
|
|
|
+ pageNo := binding.Field[int](dto, "PageNo")
|
|
|
+ pageSize := binding.Field[int](dto, "PageSize")
|
|
|
|
|
|
startCount := 1
|
|
|
- if queryParams.PageNo != 0 && queryParams.PageSize != 0 {
|
|
|
- startCount = queryParams.PageNo*queryParams.PageSize + 1
|
|
|
+ if pageNo != 0 && pageSize != 0 {
|
|
|
+ startCount = pageNo*pageSize + 1
|
|
|
}
|
|
|
|
|
|
needFindCount := len(classMap)
|
|
|
- if queryParams.PageNo != 0 && queryParams.PageSize != 0 {
|
|
|
- needFindCount = queryParams.PageSize
|
|
|
+ if pageNo != 0 && pageSize != 0 {
|
|
|
+ needFindCount = pageSize
|
|
|
}
|
|
|
|
|
|
count := 1
|
|
|
@@ -246,7 +220,7 @@ func main() {
|
|
|
return binding.InfosData[ClassInfo]{
|
|
|
Infos: classInfos,
|
|
|
TotalCount: int64(len(classMap)),
|
|
|
- PageNo: queryParams.PageNo,
|
|
|
+ PageNo: pageNo,
|
|
|
}, nil
|
|
|
},
|
|
|
})
|
|
|
@@ -257,14 +231,9 @@ func main() {
|
|
|
ResponseFunc: binding.SendInfoResponse[*ClassInfo],
|
|
|
DTO: &GetClassQueryParams{},
|
|
|
FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
|
|
|
- queryParams, err := binding.ToConcreteDTO[*GetClassQueryParams](dto)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
return []domain.Object{
|
|
|
&Class{
|
|
|
- ID: queryParams.ID,
|
|
|
+ ID: binding.Field[string](dto, "ID"),
|
|
|
},
|
|
|
}, nil
|
|
|
},
|