summaryrefslogtreecommitdiff
path: root/src/web_frontend/asset.rs
blob: 58960f91ef7c6b1fa34ecbd66e7c00b304a3fd31 (plain)
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
37
38
39
40
use std::collections::HashMap;
use rocket_contrib::templates::Template;
use crate::parsers::ini::IniFile;
use crate::parsers::csv::CsvFile;
use chrono::Utc;


#[derive(Serialize)]
pub struct AssetContext {
	accounts : Vec<Account>
}

#[derive(Serialize)]
pub struct Account {
	name : String,
	category : String,
	balance : f32
}

#[get("/asset")]
pub fn asset_handler() -> rocket_contrib::templates::Template {
	let asset_file = "data/asset.ini";
	let asset = crate::banking::asset::Asset::from_ini_file(asset_file);

	let mut acc = Vec::new();

	let today = Utc::today().naive_utc();

	for account in asset.iter() {
		let tmp = Account {
			name : account.name.to_string(),
			category : account.category.to_string(),
			balance : account.get_balance(today)
		};
		acc.push(tmp);
	}

	let context = AssetContext { accounts : acc };
	Template::render("asset", context)
}