-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
I was looking at how to implement data patching, and it appears that a working algorithm looks as follows:
- Get the patch operations in the HTTP handler (the package already does this);
- Get data you want to patch from a data store and transform it to a
map[string]interface{}; - Apply the patch operations to the data;
- Validate the patched data using Schema.Validate() function. If not valid, return a patch error;
- Transform the patched data to resource and return the resource.
If this is how the package is designed to work, it seems reasonable to implement a generic function that does data patching. Something like this:
// Apply applies the patch operation to the provided data.
func (o *PatchOperation) Apply (data map[string]interface{})Then, the handler will have a shape like this:
func (h *Handler) Patch(r *http.Request, id string, operations []scim.PatchOperation) (scim.Resource, error) {
entity := h.dataStore.Get(id)
data := userEntity.ToMap()
for _, op := range operations {
op.Apply(data)
}
if err := h.schema.Validate(data); err != nil {
// return an appropriate error
}
entity := newEntityFromData(data)
h.dataStore.Save(entity)
resource := newResourceFromEntity(entity)
return resource, nil
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels