From 9b89117a666354dd6b70be3a022fe8c915bf032a Mon Sep 17 00:00:00 2001
From: Greg Burri <greg.burri@gmail.com>
Date: Wed, 2 Apr 2025 02:14:17 +0200
Subject: [PATCH] Replace endpoint /calendar/schedule_recipe by
 /calendar/sheduled_recipe

---
 backend/src/data/db/settings.rs      | 7 ++++---
 backend/src/main.rs                  | 4 ++--
 backend/src/services/ron/calendar.rs | 2 +-
 frontend/src/recipe_scheduler.rs     | 2 +-
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/backend/src/data/db/settings.rs b/backend/src/data/db/settings.rs
index edbf351..5a96e11 100644
--- a/backend/src/data/db/settings.rs
+++ b/backend/src/data/db/settings.rs
@@ -10,16 +10,17 @@ impl Connection {
     async fn get<T>(&self, name: &str) -> Result<T>
     where
         T: FromStr,
+        T::Err: std::fmt::Display,
     {
         let v: String = sqlx::query_scalar("SELECT [value] FROM [Settings] WHERE [name] = $1")
             .bind(name)
             .fetch_one(&self.pool)
             .await?;
 
-        T::from_str(&v).map_err(|_| {
+        T::from_str(&v).map_err(|error| {
             DBError::Other(format!(
-                "Can't convert string value \"{}\" when reading setting {}",
-                v, name
+                "Can't convert string value \"{}\" when reading setting {}. Original error: {}",
+                v, name, error
             ))
         })
     }
diff --git a/backend/src/main.rs b/backend/src/main.rs
index 5470711..a4e0e92 100644
--- a/backend/src/main.rs
+++ b/backend/src/main.rs
@@ -225,8 +225,8 @@ async fn main() {
             get(services::ron::calendar::get_scheduled_recipes),
         )
         .route(
-            "/calendar/schedule_recipe",
-            post(services::ron::calendar::schedule_recipe)
+            "/calendar/scheduled_recipe",
+            post(services::ron::calendar::add_scheduled_recipe)
                 .delete(services::ron::calendar::rm_scheduled_recipe),
         )
         .route("/shopping_list", get(services::ron::shopping_list::get))
diff --git a/backend/src/services/ron/calendar.rs b/backend/src/services/ron/calendar.rs
index 8df7ccd..6ab5f6b 100644
--- a/backend/src/services/ron/calendar.rs
+++ b/backend/src/services/ron/calendar.rs
@@ -48,7 +48,7 @@ impl From<data::db::recipe::AddScheduledRecipeResult> for common::ron_api::Sched
 }
 
 #[debug_handler]
-pub async fn schedule_recipe(
+pub async fn add_scheduled_recipe(
     State(connection): State<db::Connection>,
     Extension(context): Extension<Context>,
     ExtractRon(ron): ExtractRon<common::ron_api::ScheduleRecipe>,
diff --git a/frontend/src/recipe_scheduler.rs b/frontend/src/recipe_scheduler.rs
index 2376092..63a4672 100644
--- a/frontend/src/recipe_scheduler.rs
+++ b/frontend/src/recipe_scheduler.rs
@@ -130,7 +130,7 @@ impl RecipeScheduler {
             Ok(ScheduleRecipeResult::Ok)
         } else {
             request::post::<ron_api::ScheduleRecipeResult, _>(
-                "calendar/schedule_recipe",
+                "calendar/scheduled_recipe",
                 ron_api::ScheduleRecipe {
                     recipe_id,
                     date,
-- 
2.49.0