Add delete endpoint
This commit is contained in:
16
view/who.go
16
view/who.go
@@ -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"}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user