+ Adding /neighbor/remove route api code and db-lib code
This patch has not yet been tested but will be in the coming patches Sumamary: we're just doing a regular delete on the neighbor's table based off the url field
This commit is contained in:
parent
e94c720332
commit
fbcf16b735
@ -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(())
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -123,3 +123,16 @@ pub async fn update_neighbor(p: &Pool, response: &mut Response<Body>, params: Ha
|
||||
_ => *response.status_mut() = StatusCode::BAD_REQUEST
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn remove_neighbor(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
||||
match params.get("url") {
|
||||
Some(url) => {
|
||||
// As usual 500 on server errors otherwise there's nothing to do
|
||||
if let Err(e) = db::neighbors::remove(p, url).await {
|
||||
eprintln!("[HTTP] [DB-LIB] /neighbor/remove {}", e);
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
},
|
||||
None => *response.status_mut() = StatusCode::BAD_REQUEST
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ pub const SET_NEW_ADMIN: Rstr = "/owner/newadmin"; // @requiers: ow
|
||||
pub const GET_NEIGHBORS: Rstr = "/neighbor/list"; // @requires: none @note must be a member for this list
|
||||
pub const ADD_NEIGHBOR: Rstr = "/neighbor/add"; // @requires: perm::add_neighbor
|
||||
pub const UPDATE_NEIGHBOR: Rstr = "/neighbor/update"; // @requires perms::add_neighbor @url(unique)
|
||||
pub const REMOVE_NEIGHBOR: Rstr = "/neighbor/delete"; // @requires perms::add_neighbor @url(unique)
|
||||
|
||||
pub fn is_open(path: &str) -> bool {
|
||||
return path.starts_with("/join") || path.starts_with("/meta");
|
||||
|
Loading…
Reference in New Issue
Block a user