Add delete endpoint

This commit is contained in:
Bel LaPointe
2020-07-23 21:20:08 -06:00
parent bdfc1c346b
commit 5af3f6f7b6
2 changed files with 40 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ func who(g storage.Graph, w http.ResponseWriter, r *http.Request) error {
return whoPut(namespace, g, w, r)
case http.MethodPost:
return whoPost(namespace, g, w, r)
case http.MethodDelete:
return whoDelete(namespace, g, w, r)
default:
http.NotFound(w, r)
return nil
@@ -134,3 +136,17 @@ func whoPost(namespace string, g storage.Graph, w http.ResponseWriter, r *http.R
return whoGet(namespace, g, w, r)
}
func whoDelete(namespace string, g storage.Graph, w http.ResponseWriter, r *http.Request) error {
id := r.URL.Query().Get("id")
if id == "" {
http.Error(w, `{"error":"no ?id provided"}`, http.StatusBadRequest)
return nil
}
if err := g.Delete(r.Context(), namespace, entity.One{Name: id}); err != nil {
return err
}
return json.NewEncoder(w).Encode(`{"status":"ok"}`)
}