Add delete endpoint
parent
bdfc1c346b
commit
5af3f6f7b6
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"}`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,30 @@ func TestWho(t *testing.T) {
|
|||
b, _ = json.MarshalIndent(o, "", " ")
|
||||
t.Logf("POST POST:\n%s", b)
|
||||
})
|
||||
|
||||
t.Run("delete real", func(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodDelete, "/who/col?id=NEWBIE"+want.Name, nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
r = httptest.NewRequest(http.MethodGet, "/who/col?id=NEWBIE"+want.Name, nil)
|
||||
w = httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusNotFound {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("delete fake", func(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodDelete, "/who/col?id=FAKER"+want.Name, nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func fillDB(t *testing.T, g storage.Graph) []entity.One {
|
||||
|
|
|
|||
Loading…
Reference in New Issue