summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml10
-rw-r--r--cli/src/api.rs3
-rw-r--r--cli/src/api/client.rs23
-rw-r--r--cli/src/main.rs34
4 files changed, 70 insertions, 0 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
new file mode 100644
index 0000000..9019268
--- /dev/null
+++ b/cli/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "faktura"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+serde = { version = "1.0", features = ["derive"] }
+ureq = { version = "2.9.6", features = ["json", "native-certs"] }
diff --git a/cli/src/api.rs b/cli/src/api.rs
new file mode 100644
index 0000000..be467d5
--- /dev/null
+++ b/cli/src/api.rs
@@ -0,0 +1,3 @@
+pub mod client;
+
+pub use client::Client;
diff --git a/cli/src/api/client.rs b/cli/src/api/client.rs
new file mode 100644
index 0000000..4e6a2b0
--- /dev/null
+++ b/cli/src/api/client.rs
@@ -0,0 +1,23 @@
+
+use serde::Deserialize;
+use std::error::Error;
+
+#[derive(Debug, Deserialize)]
+pub struct Client {
+ pub id: u32,
+ pub name: String,
+ pub contact: Option<String>,
+ pub address: Option<String>,
+ pub email: String,
+ pub phone: Option<String>,
+ 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()?)
+ }
+}
diff --git a/cli/src/main.rs b/cli/src/main.rs
new file mode 100644
index 0000000..906262a
--- /dev/null
+++ b/cli/src/main.rs
@@ -0,0 +1,34 @@
+// Command line app for the faktura invicing system
+//
+// SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri
+// SPDX-FileCopyrightText: 2024 Harald Eilertsen
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+mod api;
+
+use api::Client;
+
+fn main() -> Result<(), Box<dyn std::error::Error>> {
+
+ let clients = Client::all()?;
+
+ for c in clients {
+ print!("{}: {} <{}>", c.id, c.name, c.email);
+ if let Some(contact) = c.contact {
+ print!(", c/o {}", contact);
+ }
+ if let Some(address) = c.address {
+ print!(", {}", address);
+ }
+ if let Some(phone) = c.phone {
+ print!(", ph: {}", phone);
+ }
+ if c.vat {
+ print!(", VAT");
+ }
+ println!("");
+ }
+
+ Ok(())
+}