+ Debug to Neighbor struct

* add_neighbor now takes a moved Neighbor param instead of the fields individually
This should make it a easier for both front & backend to parse what's happening.
It also let's us leveraege serde_json a bit more
This commit is contained in:
shockrah 2021-05-11 17:18:17 -07:00
parent 664b837f13
commit 666894af0e
2 changed files with 7 additions and 6 deletions

View File

@ -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<String>,

View File

@ -16,17 +16,18 @@ pub async fn get_all(p: &Pool) -> SqlResult<Vec<Neighbor>> {
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?;