Impl delete find filters for boltdb

This commit is contained in:
Bel LaPointe
2020-07-23 16:41:50 -06:00
parent 085150a7b5
commit bed265a228
13 changed files with 670 additions and 92 deletions

49
view/httpisnow.go Normal file
View File

@@ -0,0 +1,49 @@
package view
import (
"fmt"
"io/ioutil"
"local/dndex/storage"
"local/dndex/storage/entity"
"local/dndex/storage/operator"
"net/http"
"path"
"github.com/buger/jsonparser"
)
func httpisnow(g storage.Graph, w http.ResponseWriter, r *http.Request) error {
namespace := path.Base(r.URL.Path)
b, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
name, err := jsonparser.GetString(b, entity.JSONName)
if err != nil {
return fmt.Errorf("cannot find %q: %v", entity.JSONName, err)
}
if name == "" {
http.Error(w, `{"error":"must provide a name"}`, http.StatusBadRequest)
return nil
}
key, err := jsonparser.GetString(b, "set", "key")
if err != nil {
return fmt.Errorf("cannot find %q: %v", "set.key", err)
}
if key == "" {
http.Error(w, `{"error":"must provide a set.key"}`, http.StatusBadRequest)
return nil
}
value, err := jsonparser.GetString(b, "set", "value")
if err != nil {
return fmt.Errorf("cannot find %q: %v", "set.value", err)
}
operator := operator.Set{Key: key, Value: value}
return g.Update(r.Context(), namespace, entity.One{Name: name}, operator)
}