diff --git a/json-api/db/src/neighbors.rs b/json-api/db/src/neighbors.rs index 9804251..d75c3b3 100644 --- a/json-api/db/src/neighbors.rs +++ b/json-api/db/src/neighbors.rs @@ -73,3 +73,10 @@ pub async fn update(p: &Pool, url: &str, new: Neighbor) -> SqlResult<()> { conn.exec_drop(q, sqlparams).await?; Ok(()) } + +pub async fn remove(p: &Pool, url: &str) -> SqlResult<()> { + let mut conn = p.get_conn().await?; + let q = "DELETE FROM neighbors WHERE url = :url"; + conn.exec_drop(q, params!{"url" => url}).await?; + Ok(()) +} diff --git a/json-api/src/main.rs b/json-api/src/main.rs index 2ff3e16..343b22e 100644 --- a/json-api/src/main.rs +++ b/json-api/src/main.rs @@ -92,6 +92,7 @@ async fn route_dispatcher( (GET, routes::GET_NEIGHBORS) => meta::server_neighbors(pool, resp).await, (POST, routes::ADD_NEIGHBOR) => meta::add_neighbor(pool, resp, body).await, (PUT, routes::UPDATE_NEIGHBOR) => meta::update_neighbor(pool, resp, params, body).await, + (DELETE, routes::REMOVE_NEIGHBOR) => meta::remove_neighbor(pool, resp, params).await, _ => { println!("[HTTP]\tNOT FOUND: {}: {}", meth, path); *resp.status_mut() = StatusCode::NOT_FOUND diff --git a/json-api/src/meta.rs b/json-api/src/meta.rs index 51e3f22..fb9ebd4 100644 --- a/json-api/src/meta.rs +++ b/json-api/src/meta.rs @@ -123,3 +123,16 @@ pub async fn update_neighbor(p: &Pool, response: &mut Response
, params: Ha _ => *response.status_mut() = StatusCode::BAD_REQUEST } } + +pub async fn remove_neighbor(p: &Pool, response: &mut Response, params: HashMap