summaryrefslogtreecommitdiffstats
path: root/cli/src/api/client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/api/client.rs')
-rw-r--r--cli/src/api/client.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/cli/src/api/client.rs b/cli/src/api/client.rs
index eee59b0..9c46db3 100644
--- a/cli/src/api/client.rs
+++ b/cli/src/api/client.rs
@@ -3,25 +3,34 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
use std::error::Error;
+use super::Connection;
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Client {
+ #[serde(default)]
pub id: u32,
+
pub name: String,
pub contact: Option<String>,
pub address: Option<String>,
pub email: String,
pub phone: Option<String>,
+
+ #[serde(default)]
pub vat: bool,
}
impl Client {
- pub fn all() -> Result<Vec<Self>, Box<dyn Error>> {
- Ok(ureq::get("http://faktura.ddev.site/api/clients")
- .set("Accept", "application/json")
- .call()?
- .into_json()?)
+ pub fn all(conn: Connection) -> Result<Vec<Self>, Box<dyn Error>> {
+ Ok(conn.get("clients")?)
+ }
+
+ pub fn save(&self, conn: Connection) -> Result<(), Box<dyn Error>> {
+ let resp = conn.post("clients", &self)?;
+
+ println!("{}", resp);
+ Ok(())
}
}