diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-07-28 23:46:25 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-07-28 23:46:25 +0200 |
| commit | 97595d132fba62a84110e9df799c303b18d3b462 (patch) | |
| tree | 24b1d4302ec12aeb6d9471299d26e389ffd40e51 /cli/src | |
| download | money-97595d132fba62a84110e9df799c303b18d3b462.tar.gz | |
initial commit
Diffstat (limited to 'cli/src')
| -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(); +} |
