yjp 1 anno fa
parent
commit
d2fa08e7ad
1 ha cambiato i file con 26 aggiunte e 5 eliminazioni
  1. 26 5
      examples/binding/main.go

+ 26 - 5
examples/binding/main.go

@@ -12,6 +12,12 @@ import (
 	"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":"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"
+
 type CreateClassJsonBody struct {
 	Name string `json:"name" binding:"required"`
 }
@@ -89,7 +95,7 @@ func main() {
 
 	// 删除班级
 	binding.DeleteBind(v1Router, &binding.SimpleBindItem[any]{
-		Path:         "/class/delete",
+		Path:         "/class/:id/delete",
 		ResponseFunc: binding.SendMsgResponse,
 		DTO:          &DeleteClassPathParams{},
 		FormDomainObjectsFunc: func(c *api.Context, dto binding.DTO) ([]domain.Object, error) {
@@ -201,19 +207,34 @@ func main() {
 				startCount = queryParams.PageNo*queryParams.PageSize + 1
 			}
 
-			endCount := len(classMap)
+			needFindCount := len(classMap)
 			if queryParams.PageNo != 0 && queryParams.PageSize != 0 {
-				endCount = queryParams.PageSize
+				needFindCount = queryParams.PageSize
 			}
 
 			count := 1
+			findCount := 0
+
 			for _, existEntity := range classMap {
-				if count >= endCount {
+				if count <
+
+				if findCount >= needFindCount {
 					break
 				}
 
 				if count >= startCount {
-					if existEntity.Name == e.Name {
+					find := false
+					if strutils.IsStringNotEmpty(e.Name) {
+						if existEntity.Name == e.Name {
+							find = true
+							findCount++
+						}
+					} else {
+						find = true
+						findCount++
+					}
+
+					if find {
 						classInfos = append(classInfos, ClassInfo{
 							ID:   existEntity.ID,
 							Name: existEntity.Name,