diff options
Diffstat (limited to 'cli/src/main.rs')
| -rw-r--r-- | cli/src/main.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs new file mode 100644 index 0000000..a43bbca --- /dev/null +++ b/cli/src/main.rs @@ -0,0 +1,59 @@ +use rust_decimal::Decimal; +use serde::{Deserialize, Serialize}; +use std::convert::{AsRef, TryFrom}; +use std::fs; +use std::path::Path; + +type Account = String; +type Category = String; + +#[derive(Debug)] +#[derive(Deserialize, Serialize)] +enum TransactionKind { + Expense, + Income, + //TODO Transfer, +} + +#[derive(Debug)] +#[derive(Deserialize, Serialize)] +struct Transaction { + description: String, + category: Category, + amount: Decimal, + kind: TransactionKind, + from: Account, + to: Account, +} + +#[derive(Debug)] +#[derive(Deserialize, Serialize)] +struct Post { + transaction: Transaction, + removed: bool, +} + +impl Post { + fn new(transaction: Transaction) -> Self { + Self { + transaction, + removed: false, + } + } + + fn write<P: AsRef<Path>>(&self, p: &P) -> std::io::Result<()> { + fs::write(p, serde_json::to_string_pretty(self).unwrap()) //TODO control pretty or not + } +} + +fn main() { + let post = Post::new(Transaction { + description: "Test".to_string(), + category: "Mat".to_string(), + amount: Decimal::try_from(120.4_f64).unwrap(), + kind: TransactionKind::Expense, + from: "Kortkonto".to_string(), + to: "Coop Lambohov".to_string(), + }); + post.write(&"test").unwrap(); +} |
