diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/controller/balance.rs | 6 | ||||
| -rw-r--r-- | src/controller/balancing.rs | 12 | ||||
| -rw-r--r-- | src/db/balancing.rs | 8 | ||||
| -rw-r--r-- | src/routes.rs | 3 | ||||
| -rw-r--r-- | src/validation/balancing.rs | 4 |
5 files changed, 20 insertions, 13 deletions
diff --git a/src/controller/balance.rs b/src/controller/balance.rs index 6cb937b..9398dae 100644 --- a/src/controller/balance.rs +++ b/src/controller/balance.rs @@ -6,8 +6,8 @@ use std::collections::HashMap; use crate::controller::utils; use crate::controller::wallet::Wallet; use crate::db; -use crate::model::user::User; use crate::model::balancing::Balancing; +use crate::model::user::User; use crate::payer; use crate::templates; @@ -25,7 +25,7 @@ pub async fn get(wallet: &Wallet) -> Response<Full<Bytes>> { let user_payments = with_balancing( db::payments::repartition(&wallet.db_conn).await, - db::balancing::list(&wallet.db_conn).await + db::balancing::list(&wallet.db_conn).await, ); let template_user_payments = get_template_user_payments(&users, &user_payments); @@ -74,7 +74,7 @@ fn get_template_user_incomes( fn with_balancing( user_payments: HashMap<i64, i64>, - balancings: Vec<Balancing> + balancings: Vec<Balancing>, ) -> HashMap<i64, i64> { let mut user_payments = user_payments; for balancing in balancings { diff --git a/src/controller/balancing.rs b/src/controller/balancing.rs index 718358c..c3d5ee8 100644 --- a/src/controller/balancing.rs +++ b/src/controller/balancing.rs @@ -18,7 +18,8 @@ pub async fn table( ) -> Response<Full<Bytes>> { let page = query.page.unwrap_or(1); let count = db::balancing::count(&wallet.db_conn).await; - let balancings = db::balancing::list_for_table(&wallet.db_conn, page, PER_PAGE).await; + let balancings = + db::balancing::list_for_table(&wallet.db_conn, page, PER_PAGE).await; let max_page = (count as f32 / PER_PAGE as f32).ceil() as i64; let context = minijinja::context!( @@ -70,7 +71,6 @@ async fn create_form_feedback( ) } - pub async fn create( wallet: &Wallet, query: queries::Balancing, @@ -84,8 +84,7 @@ pub async fn create( Some(balancing) => { match db::balancing::create(&wallet.db_conn, balancing).await { Some(id) => { - let row = - db::balancing::get_row(&wallet.db_conn, id).await; + let row = db::balancing::get_row(&wallet.db_conn, id).await; let page = (row - 1) / PER_PAGE + 1; utils::redirect(&format!( "/balancings?page={}&highlight={}", @@ -175,7 +174,10 @@ pub async fn delete( query: queries::Balancing, ) -> Response<Full<Bytes>> { if db::balancing::delete(&wallet.db_conn, id).await { - utils::redirect(&format!("/balancings?page={}", query.page.unwrap_or(1))) + utils::redirect(&format!( + "/balancings?page={}", + query.page.unwrap_or(1) + )) } else { update_form_feedback( id, diff --git a/src/db/balancing.rs b/src/db/balancing.rs index 8914eef..379576b 100644 --- a/src/db/balancing.rs +++ b/src/db/balancing.rs @@ -1,7 +1,7 @@ use tokio_rusqlite::{Connection, Row, named_params}; use crate::db::utils; -use crate::model::balancing::{Balancing, Create, Update, TableRow}; +use crate::model::balancing::{Balancing, Create, TableRow, Update}; fn row_to_balancing(row: &Row) -> Result<Balancing, rusqlite::Error> { Ok(Balancing { @@ -36,7 +36,11 @@ pub async fn count(conn: &Connection) -> i64 { } } -pub async fn list_for_table(conn: &Connection, page: i64, per_page: i64) -> Vec<TableRow> { +pub async fn list_for_table( + conn: &Connection, + page: i64, + per_page: i64, +) -> Vec<TableRow> { let query = r#" SELECT balancing.id, diff --git a/src/routes.rs b/src/routes.rs index 3afc822..ed8db5f 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -200,7 +200,8 @@ async fn authenticated_routes( controller::balancing::table(&wallet, parse_query(query)).await } (&Method::GET, ["balancing"]) => { - controller::balancing::create_form(&wallet, parse_query(query)).await + controller::balancing::create_form(&wallet, parse_query(query)) + .await } (&Method::POST, ["balancing", "create"]) => { controller::balancing::create( diff --git a/src/validation/balancing.rs b/src/validation/balancing.rs index 8892bca..3b70eea 100644 --- a/src/validation/balancing.rs +++ b/src/validation/balancing.rs @@ -13,7 +13,7 @@ pub fn create(form: &HashMap<String, String>) -> Option<Create> { Some(Create { source, destination, - amount: parse::<i64>(form, "amount")? + amount: parse::<i64>(form, "amount")?, }) } } @@ -28,7 +28,7 @@ pub fn update(form: &HashMap<String, String>) -> Option<Update> { Some(Update { source, destination, - amount: parse::<i64>(form, "amount")? + amount: parse::<i64>(form, "amount")?, }) } } |
