diff --git a/json-api/db/src/lib.rs b/json-api/db/src/lib.rs index e8848ec..0de94d3 100644 --- a/json-api/db/src/lib.rs +++ b/json-api/db/src/lib.rs @@ -92,7 +92,7 @@ pub struct PublicMember { pub permissions: UBigInt, } -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Neighbor { pub name: String, pub description: Option, diff --git a/json-api/db/src/neighbors.rs b/json-api/db/src/neighbors.rs index 4dd111e..9804251 100644 --- a/json-api/db/src/neighbors.rs +++ b/json-api/db/src/neighbors.rs @@ -16,17 +16,18 @@ pub async fn get_all(p: &Pool) -> SqlResult> { Ok(set) } -pub async fn add_neighbor(p: &Pool, url: &str, wsurl: &str, name: &str, desc: &str, tags:&str) -> SqlResult<()> { +pub async fn add_neighbor(p: &Pool, new: Neighbor) -> SqlResult<()> { // Note we assume that the tags field has been verified as proper valid json prior to // writing it to the db let mut conn = p.get_conn().await?; let q = "INSERT INTO neighbors(url, wsurl, name, description, tags) VALUES(:url, :wsurl, :name, :desc, :tags)"; + let tags = serde_json::to_string(&new.tags).unwrap_or("[]".to_string()); let sqlparams = params!{ - "url"=> url, - "wsurl"=>wsurl, - "name"=>name, - "desc"=>desc, + "url"=> new.url, + "wsurl"=>new.wsurl, + "name"=>new.name, + "desc"=>new.description, "tags"=>tags }; conn.exec_drop(q, sqlparams).await?;