summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/src/api/client.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/cli/src/api/client.rs b/cli/src/api/client.rs
index 9c46db3..c77063b 100644
--- a/cli/src/api/client.rs
+++ b/cli/src/api/client.rs
@@ -4,6 +4,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
use serde::{Deserialize, Serialize};
+use serde_json::json;
use std::error::Error;
use super::Connection;
@@ -28,7 +29,20 @@ impl Client {
}
pub fn save(&self, conn: Connection) -> Result<(), Box<dyn Error>> {
- let resp = conn.post("clients", &self)?;
+ // By default the `id` of a newly created client will be 0,
+ // which will cause the API to add the client with id=0. This works once
+ // but then fails for the next clients added.
+ //
+ // To fix this, we remove the `id` from the json payload before
+ // we pass it to the API.
+ let mut json = json!(&self)
+ .as_object()
+ .ok_or("not an object")?
+ .clone();
+
+ json.remove("id");
+
+ let resp = conn.post("clients", &json)?;
println!("{}", resp);
Ok(())