1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri
// SPDX-FileCopyrightText: 2024 Harald Eilertsen
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use serde::{Deserialize, Serialize};
use std::error::Error;
use super::Connection;
#[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(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(())
}
}
|