From 5638fc4979d14fff8bbfa791c0abdf50f7ff084c Mon Sep 17 00:00:00 2001 From: Simon Bernier St-Pierre Date: Mon, 3 Aug 2026 21:35:40 -0400 Subject: [PATCH] fmt & version 0.3.0 [skip ci] --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/http.rs | 10 +++++-- src/services.rs | 10 ++++--- src/sqlite.rs | 70 ++++++++++++++++++++++++++++--------------------- 5 files changed, 56 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6e5283..9ce1a85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1772,7 +1772,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sustenance" -version = "0.2.0" +version = "0.3.0" dependencies = [ "argon2", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 8939e16..41fb162 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sustenance" -version = "0.2.0" +version = "0.3.0" edition = "2024" [dependencies] diff --git a/src/http.rs b/src/http.rs index 1522315..d55e13f 100644 --- a/src/http.rs +++ b/src/http.rs @@ -105,7 +105,10 @@ pub fn build_router(state: AppState) -> Router { .route("/meals", get(meals_page).post(create_meal)) .route("/meals/new", get(new_meal_page)) .route("/meals/categories", post(create_meal_category)) - .route("/meals/categories/{category_id}/delete", post(delete_meal_category)) + .route( + "/meals/categories/{category_id}/delete", + post(delete_meal_category), + ) .route("/meals/{meal_id}", get(meal_page)) .route("/meals/{meal_id}/edit", post(edit_meal)) .route("/meals/{meal_id}/delete", post(delete_meal)) @@ -485,7 +488,10 @@ async fn change_password( }; if form.new_password != form.confirm_password { - return Ok(render(Some("New password and confirmation do not match."), false)); + return Ok(render( + Some("New password and confirmation do not match."), + false, + )); } state diff --git a/src/services.rs b/src/services.rs index 67e3cb0..5ade949 100644 --- a/src/services.rs +++ b/src/services.rs @@ -351,9 +351,9 @@ impl MealService { let meals = Arc::clone(&self.meals); self.db .run(move |txn| { - Box::pin(async move { - meals.create_meal(txn, name, description, category_id).await - }) + Box::pin( + async move { meals.create_meal(txn, name, description, category_id).await }, + ) }) .await } @@ -411,7 +411,9 @@ impl MealService { let meal_categories = Arc::clone(&self.meal_categories); self.db .run(move |txn| { - Box::pin(async move { meal_categories.delete_meal_category(txn, category_id).await }) + Box::pin( + async move { meal_categories.delete_meal_category(txn, category_id).await }, + ) }) .await } diff --git a/src/sqlite.rs b/src/sqlite.rs index 85a267e..1994773 100644 --- a/src/sqlite.rs +++ b/src/sqlite.rs @@ -130,15 +130,13 @@ async fn seed_default_meal_categories(pool: &SqlitePool) -> DomainResult<()> { return Ok(()); } for (position, category_name) in DEFAULT_MEAL_CATEGORIES.iter().enumerate() { - sqlx::query( - "INSERT INTO meal_categories (name, position, created_at) VALUES (?1, ?2, ?3)", - ) - .bind(category_name) - .bind(position as i64) - .bind(now()) - .execute(pool) - .await - .map_err(db_error)?; + sqlx::query("INSERT INTO meal_categories (name, position, created_at) VALUES (?1, ?2, ?3)") + .bind(category_name) + .bind(position as i64) + .bind(now()) + .execute(pool) + .await + .map_err(db_error)?; } Ok(()) } @@ -833,11 +831,12 @@ impl MealCategoryRepository for SqliteMealCategoryRepository { txn: &mut SqliteConnection, name: String, ) -> DomainResult { - let position: i64 = sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM meal_categories") - .fetch_one(&mut *txn) - .await - .map_err(db_error)? - .get(0); + let position: i64 = + sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM meal_categories") + .fetch_one(&mut *txn) + .await + .map_err(db_error)? + .get(0); let result = sqlx::query( "INSERT INTO meal_categories (name, position, created_at) VALUES (?1, ?2, ?3)", @@ -1181,14 +1180,8 @@ const DEFAULT_CATEGORIES: &[&str] = &[ "Household", ]; -const DEFAULT_MEAL_CATEGORIES: &[&str] = &[ - "Beef", - "Chicken", - "Pasta", - "Sandwiches", - "Salads", - "Soups", -]; +const DEFAULT_MEAL_CATEGORIES: &[&str] = + &["Beef", "Chicken", "Pasta", "Sandwiches", "Salads", "Soups"]; fn hash_secret(secret: &str) -> Vec { let mut hasher = Sha256::new(); @@ -1609,7 +1602,10 @@ mod tests { async fn meal_categories_are_seeded_with_defaults() { let db = setup().await; let categories = get_meal_categories(&db).await; - let names = categories.iter().map(|c| c.name.as_str()).collect::>(); + let names = categories + .iter() + .map(|c| c.name.as_str()) + .collect::>(); assert!(names.contains(&"Beef")); assert!(names.contains(&"Chicken")); assert!(names.contains(&"Pasta")); @@ -1626,7 +1622,9 @@ mod tests { .run(move |txn| { let categories = categories.clone(); Box::pin(async move { - categories.create_meal_category(txn, "Breakfast".into()).await + categories + .create_meal_category(txn, "Breakfast".into()) + .await }) }) .await @@ -1643,9 +1641,7 @@ mod tests { let result = db .run(move |txn| { let categories = categories.clone(); - Box::pin(async move { - categories.create_meal_category(txn, "Beef".into()).await - }) + Box::pin(async move { categories.create_meal_category(txn, "Beef".into()).await }) }) .await; assert!(matches!(result, Err(DomainError::Conflict))); @@ -1659,7 +1655,9 @@ mod tests { .run(move |txn| { let categories = categories.clone(); Box::pin(async move { - categories.create_meal_category(txn, "Breakfast".into()).await + categories + .create_meal_category(txn, "Breakfast".into()) + .await }) }) .await @@ -1670,7 +1668,13 @@ mod tests { let meals = meals.clone(); Box::pin(async move { meals - .update_meal(txn, meal.id, "Pancakes".into(), String::new(), Some(category_id)) + .update_meal( + txn, + meal.id, + "Pancakes".into(), + String::new(), + Some(category_id), + ) .await }) }) @@ -2162,7 +2166,13 @@ mod tests { let meals = meals.clone(); Box::pin(async move { meals - .update_meal(txn, meal.id, "Pasta al pomodoro".into(), "desc".into(), None) + .update_meal( + txn, + meal.id, + "Pasta al pomodoro".into(), + "desc".into(), + None, + ) .await }) })