summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenedict Börger <benedict@0xb8000.de>2019-06-26 23:54:49 +0200
committerBenedict Börger <benedict@0xb8000.de>2019-06-26 23:54:49 +0200
commit04c9461ef53f5eaa8e7d72442e211d91546b88e3 (patch)
tree98c87604825c4fe6016a2ee64c6324be4da09242 /src
parentf3080c9575baac69cc5355f09dd82d44bf77b0d4 (diff)
[web_fronted][asset] use new iterator over Asset
Diffstat (limited to 'src')
-rw-r--r--src/web_frontend/asset.rs37
1 files changed, 8 insertions, 29 deletions
diff --git a/src/web_frontend/asset.rs b/src/web_frontend/asset.rs
index f69f184..58960f9 100644
--- a/src/web_frontend/asset.rs
+++ b/src/web_frontend/asset.rs
@@ -2,6 +2,7 @@ use std::collections::HashMap;
use rocket_contrib::templates::Template;
use crate::parsers::ini::IniFile;
use crate::parsers::csv::CsvFile;
+use chrono::Utc;
#[derive(Serialize)]
@@ -19,39 +20,17 @@ pub struct Account {
#[get("/asset")]
pub fn asset_handler() -> rocket_contrib::templates::Template {
let asset_file = "data/asset.ini";
- let asset_config = IniFile::from_file(asset_file);
- let ini_file;
- match asset_config {
- Ok(file) => ini_file = file,
- Err(e) => panic!("could not read asset file")
- }
+ let asset = crate::banking::asset::Asset::from_ini_file(asset_file);
let mut acc = Vec::new();
- for (account_name, config) in ini_file.sections {
- let mut category = String::from("");
- if let Some(cat) = config.get("Category") {
- if let Some(c) = cat.get(0) {
- category = c.to_string();
- }
- }
- let mut all_trans = Vec::new();
- if let Some(transaction_files) = config.get("TransactionFile") {
- for file in transaction_files {
- let transactions = CsvFile::from_file(file, ";", true);
- let mut t : Vec<crate::banking::account::Transaction> ;
- match transactions {
- Ok(trans) => t = crate::banking::account::Transaction::from_sparkasse_csv_file(trans),
- Err(e) => panic!("could not read file {:?}", e)
- }
- all_trans.append(& mut t);
- }
- }
- let balance = all_trans.iter().fold(0.0, |acc, x| acc + x.amount).abs();
+ let today = Utc::today().naive_utc();
+
+ for account in asset.iter() {
let tmp = Account {
- name : account_name,
- category : category.to_string(),
- balance : balance
+ name : account.name.to_string(),
+ category : account.category.to_string(),
+ balance : account.get_balance(today)
};
acc.push(tmp);
}