From 11052951b74b9ad4b6a9412ae490086235f9154b Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 3 Jan 2021 13:40:40 +0100 Subject: Rewrite in Rust --- src/controller/statistics.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/controller/statistics.rs (limited to 'src/controller/statistics.rs') diff --git a/src/controller/statistics.rs b/src/controller/statistics.rs new file mode 100644 index 0000000..38a5787 --- /dev/null +++ b/src/controller/statistics.rs @@ -0,0 +1,30 @@ +use hyper::{Body, Response}; +use tera::Context; + +use crate::controller::utils; +use crate::controller::wallet::Wallet; +use crate::db; +use crate::templates; + +pub async fn get(wallet: &Wallet) -> Response { + let categories = db::categories::list(&wallet.pool).await; + let payments = db::payments::list_for_stats(&wallet.pool).await; + let incomes = db::incomes::total_each_month(&wallet.pool).await; + + let mut context = Context::new(); + context.insert("header", &templates::Header::Statistics); + context.insert("connected_user", &wallet.user); + context.insert( + "json_categories", + &serde_json::to_string(&categories).unwrap(), + ); + context.insert("json_payments", &serde_json::to_string(&payments).unwrap()); + context.insert("json_incomes", &serde_json::to_string(&incomes).unwrap()); + + utils::template( + &wallet.assets, + &wallet.templates, + "statistics.html", + context, + ) +} -- cgit v1.2.3