Jaycean commented on a change in pull request #1395:
URL: https://github.com/apache/apisix-dashboard/pull/1395#discussion_r567543459
##########
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]