Jaycean commented on a change in pull request #1395:
URL: https://github.com/apache/apisix-dashboard/pull/1395#discussion_r567209410



##########
File path: api/internal/handler/upstream/upstream.go
##########
@@ -198,39 +201,36 @@ func (h *Handler) BatchDelete(c droplet.Context) 
(interface{}, error) {
        return nil, nil
 }
 
+type PatchInput struct {
+       ID      string `auto_read:"id,path"`
+       SubPath string `auto_read:"path,path"`
+       Body    []byte `auto_read:"@body"`
+}
+
 func (h *Handler) Patch(c droplet.Context) (interface{}, error) {
-       input := c.Input().(*UpdateInput)
-       arr := strings.Split(input.ID, "/")
-       var subPath string
-       if len(arr) > 1 {
-               input.ID = arr[0]
-               subPath = arr[1]
-       }
+       input := c.Input().(*PatchInput)
+       reqBody := input.Body
+       ID := input.ID

Review comment:
       done. Thks

##########
File path: api/internal/handler/upstream/upstream.go
##########
@@ -17,11 +17,11 @@
 package upstream
 
 import (
+       "encoding/json"
        "net/http"
        "reflect"
        "strings"
 
-       "github.com/api7/go-jsonpatch"

Review comment:
       done.Thanks for the reminder

##########
File path: api/internal/handler/upstream/upstream.go
##########
@@ -314,3 +314,4 @@ func (h *Handler) listUpstreamNames(c droplet.Context) 
(interface{}, error) {
 
        return output, nil
 }
+

Review comment:
       This is my problem. Maybe I forgot to delete it when using vim. Done. 
Thks

##########
File path: api/internal/handler/upstream/upstream.go
##########
@@ -198,39 +201,36 @@ func (h *Handler) BatchDelete(c droplet.Context) 
(interface{}, error) {
        return nil, nil
 }
 
+type PatchInput struct {
+       ID      string `auto_read:"id,path"`
+       SubPath string `auto_read:"path,path"`
+       Body    []byte `auto_read:"@body"`
+}
+
 func (h *Handler) Patch(c droplet.Context) (interface{}, error) {
-       input := c.Input().(*UpdateInput)
-       arr := strings.Split(input.ID, "/")
-       var subPath string
-       if len(arr) > 1 {
-               input.ID = arr[0]
-               subPath = arr[1]
-       }
+       input := c.Input().(*PatchInput)
+       reqBody := input.Body
+       ID := input.ID
+       subPath := input.SubPath
 
-       stored, err := h.upstreamStore.Get(c.Context(), input.ID)
+       stored, err := h.upstreamStore.Get(c.Context(), ID)
        if err != nil {
                return handler.SpecCodeResponse(err), err
        }
 
-       var patch jsonpatch.Patch
-       if subPath != "" {
-               patch = jsonpatch.Patch{
-                       Operations: []jsonpatch.PatchOperation{
-                               {Op: jsonpatch.Replace, Path: subPath, Value: 
c.Input()},
-                       },
-               }
-       } else {
-               patch, err = jsonpatch.MakePatch(stored, input.Upstream)
-               if err != nil {
-                       return handler.SpecCodeResponse(err), err
-               }
+       res, err := utils.MergePatch(stored, subPath, reqBody)
+
+       if err != nil {
+               return handler.SpecCodeResponse(err), err
        }
 
-       if err := patch.Apply(&stored); err != nil {
+       var upstream entity.Upstream
+       err = json.Unmarshal(res, &upstream)
+       if err != nil {

Review comment:
       done. Thks




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to