From 97595d132fba62a84110e9df799c303b18d3b462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 28 Jul 2021 23:46:25 +0200 Subject: initial commit --- cli/src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 cli/src/main.rs (limited to 'cli/src/main.rs') 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>(&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(); +} -- cgit v1.2.1