karsto / glew

A glorified project generator. Give it some models, out comes a low level api and vue admin ui.
0 stars 0 forks source link

Add Patch #7

Open ashtonian opened 4 years ago

ashtonian commented 4 years ago

Proper patch, multi resource, support multiple resources same query. diff between null, undefined, and "" or 0.

ashtonian commented 4 years ago

example body:

[
{
    "op":"test",
    "path":"/a/b/c",
    "value":"foo"
  },
  {
    "op":"remove",
    "path":"/a/b/c"
  },
  {
    "op":"add",
    "path":"/a/b/c",
    "value":[
      "foo",
      "bar"
    ]
  },
  {
    "op":"replace",
    "path":"/a/b/c",
    "value":42
  },
  {
    "op":"move",
    "from":"/a/b/c",
    "path":"/a/b/d"
  },
  {
    "op":"copy",
    "from":"/a/b/d",
    "path":"/a/b/e"
  }
]

limit to replace (+ maybe remove) implementation initially.

Ideal: ParseFields, verify name, verify type, verify op is allowed.

ashtonian commented 4 years ago

Patchy:

type Op struct {
Operation string 
From string 
Path String 
Value interface{}
}

// created using reflection once, then used every query to generate sql. 
type PatchSpec struct {
TargetResource string 
Fields  []PatchField
}

type PatchField struct {
AllowedOps string
TargetType string
Validator func // only need two funcs
Converter func
Filter func
}

func (op *Op) GetValue() interface{} {
} 

type Error struct {
Attempted Op
Reason string 
Code int // custom 
}

allow 201 status code with soft rejections. SQL util to generate sql statement from []OP.

ashtonian commented 4 years ago

https://tools.ietf.org/html/rfc6902

ashtonian commented 4 years ago

https://tools.ietf.org/html/rfc5789