This commit is contained in:
Generated
+1
-1
@@ -1772,7 +1772,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sustenance"
|
name = "sustenance"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "sustenance"
|
name = "sustenance"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+8
-2
@@ -105,7 +105,10 @@ pub fn build_router(state: AppState) -> Router {
|
|||||||
.route("/meals", get(meals_page).post(create_meal))
|
.route("/meals", get(meals_page).post(create_meal))
|
||||||
.route("/meals/new", get(new_meal_page))
|
.route("/meals/new", get(new_meal_page))
|
||||||
.route("/meals/categories", post(create_meal_category))
|
.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}", get(meal_page))
|
||||||
.route("/meals/{meal_id}/edit", post(edit_meal))
|
.route("/meals/{meal_id}/edit", post(edit_meal))
|
||||||
.route("/meals/{meal_id}/delete", post(delete_meal))
|
.route("/meals/{meal_id}/delete", post(delete_meal))
|
||||||
@@ -485,7 +488,10 @@ async fn change_password(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if form.new_password != form.confirm_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
|
state
|
||||||
|
|||||||
+6
-4
@@ -351,9 +351,9 @@ impl MealService {
|
|||||||
let meals = Arc::clone(&self.meals);
|
let meals = Arc::clone(&self.meals);
|
||||||
self.db
|
self.db
|
||||||
.run(move |txn| {
|
.run(move |txn| {
|
||||||
Box::pin(async move {
|
Box::pin(
|
||||||
meals.create_meal(txn, name, description, category_id).await
|
async move { meals.create_meal(txn, name, description, category_id).await },
|
||||||
})
|
)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -411,7 +411,9 @@ impl MealService {
|
|||||||
let meal_categories = Arc::clone(&self.meal_categories);
|
let meal_categories = Arc::clone(&self.meal_categories);
|
||||||
self.db
|
self.db
|
||||||
.run(move |txn| {
|
.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
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-20
@@ -130,9 +130,7 @@ async fn seed_default_meal_categories(pool: &SqlitePool) -> DomainResult<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
for (position, category_name) in DEFAULT_MEAL_CATEGORIES.iter().enumerate() {
|
for (position, category_name) in DEFAULT_MEAL_CATEGORIES.iter().enumerate() {
|
||||||
sqlx::query(
|
sqlx::query("INSERT INTO meal_categories (name, position, created_at) VALUES (?1, ?2, ?3)")
|
||||||
"INSERT INTO meal_categories (name, position, created_at) VALUES (?1, ?2, ?3)",
|
|
||||||
)
|
|
||||||
.bind(category_name)
|
.bind(category_name)
|
||||||
.bind(position as i64)
|
.bind(position as i64)
|
||||||
.bind(now())
|
.bind(now())
|
||||||
@@ -833,7 +831,8 @@ impl MealCategoryRepository for SqliteMealCategoryRepository {
|
|||||||
txn: &mut SqliteConnection,
|
txn: &mut SqliteConnection,
|
||||||
name: String,
|
name: String,
|
||||||
) -> DomainResult<i64> {
|
) -> DomainResult<i64> {
|
||||||
let position: i64 = sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM meal_categories")
|
let position: i64 =
|
||||||
|
sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM meal_categories")
|
||||||
.fetch_one(&mut *txn)
|
.fetch_one(&mut *txn)
|
||||||
.await
|
.await
|
||||||
.map_err(db_error)?
|
.map_err(db_error)?
|
||||||
@@ -1181,14 +1180,8 @@ const DEFAULT_CATEGORIES: &[&str] = &[
|
|||||||
"Household",
|
"Household",
|
||||||
];
|
];
|
||||||
|
|
||||||
const DEFAULT_MEAL_CATEGORIES: &[&str] = &[
|
const DEFAULT_MEAL_CATEGORIES: &[&str] =
|
||||||
"Beef",
|
&["Beef", "Chicken", "Pasta", "Sandwiches", "Salads", "Soups"];
|
||||||
"Chicken",
|
|
||||||
"Pasta",
|
|
||||||
"Sandwiches",
|
|
||||||
"Salads",
|
|
||||||
"Soups",
|
|
||||||
];
|
|
||||||
|
|
||||||
fn hash_secret(secret: &str) -> Vec<u8> {
|
fn hash_secret(secret: &str) -> Vec<u8> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
@@ -1609,7 +1602,10 @@ mod tests {
|
|||||||
async fn meal_categories_are_seeded_with_defaults() {
|
async fn meal_categories_are_seeded_with_defaults() {
|
||||||
let db = setup().await;
|
let db = setup().await;
|
||||||
let categories = get_meal_categories(&db).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(&"Beef"));
|
||||||
assert!(names.contains(&"Chicken"));
|
assert!(names.contains(&"Chicken"));
|
||||||
assert!(names.contains(&"Pasta"));
|
assert!(names.contains(&"Pasta"));
|
||||||
@@ -1626,7 +1622,9 @@ mod tests {
|
|||||||
.run(move |txn| {
|
.run(move |txn| {
|
||||||
let categories = categories.clone();
|
let categories = categories.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
categories.create_meal_category(txn, "Breakfast".into()).await
|
categories
|
||||||
|
.create_meal_category(txn, "Breakfast".into())
|
||||||
|
.await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
@@ -1643,9 +1641,7 @@ mod tests {
|
|||||||
let result = db
|
let result = db
|
||||||
.run(move |txn| {
|
.run(move |txn| {
|
||||||
let categories = categories.clone();
|
let categories = categories.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move { categories.create_meal_category(txn, "Beef".into()).await })
|
||||||
categories.create_meal_category(txn, "Beef".into()).await
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Conflict)));
|
assert!(matches!(result, Err(DomainError::Conflict)));
|
||||||
@@ -1659,7 +1655,9 @@ mod tests {
|
|||||||
.run(move |txn| {
|
.run(move |txn| {
|
||||||
let categories = categories.clone();
|
let categories = categories.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
categories.create_meal_category(txn, "Breakfast".into()).await
|
categories
|
||||||
|
.create_meal_category(txn, "Breakfast".into())
|
||||||
|
.await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
@@ -1670,7 +1668,13 @@ mod tests {
|
|||||||
let meals = meals.clone();
|
let meals = meals.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
meals
|
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
|
.await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -2162,7 +2166,13 @@ mod tests {
|
|||||||
let meals = meals.clone();
|
let meals = meals.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
meals
|
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
|
.await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user