fmt & version 0.3.0 [skip ci]
ci/woodpecker/tag/release Pipeline was successful

This commit is contained in:
2026-08-03 21:35:40 -04:00
parent 3695fc68d6
commit 5638fc4979
5 changed files with 56 additions and 38 deletions
Generated
+1 -1
View File
@@ -1772,7 +1772,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sustenance"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"argon2",
"async-trait",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "sustenance"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
[dependencies]
+8 -2
View File
@@ -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
+6 -4
View File
@@ -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
}
+40 -30
View File
@@ -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<i64> {
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<u8> {
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::<Vec<_>>();
let names = categories
.iter()
.map(|c| c.name.as_str())
.collect::<Vec<_>>();
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
})
})