Replace PUT method by the more appropriate PATCH method.

This commit is contained in:
Greg Burri 2025-03-18 20:02:30 +01:00
parent 8dcaac35b7
commit 9ed5a04e22
4 changed files with 46 additions and 37 deletions

View file

@ -35,7 +35,7 @@ pub fn setup_page(recipe_id: i64) {
title: title.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_title", body).await;
let _ = request::patch::<(), _>("recipe/set_title", body).await;
reload_recipes_list(recipe_id).await;
});
}
@ -56,7 +56,7 @@ pub fn setup_page(recipe_id: i64) {
description: description.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_description", body).await;
let _ = request::patch::<(), _>("recipe/set_description", body).await;
});
}
})
@ -87,7 +87,7 @@ pub fn setup_page(recipe_id: i64) {
servings,
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_servings", body).await;
let _ = request::patch::<(), _>("recipe/set_servings", body).await;
});
}
})
@ -119,7 +119,7 @@ pub fn setup_page(recipe_id: i64) {
estimated_time: time,
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_estimated_time", body).await;
let _ = request::patch::<(), _>("recipe/set_estimated_time", body).await;
});
}
})
@ -143,7 +143,7 @@ pub fn setup_page(recipe_id: i64) {
.unwrap(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_difficulty", body).await;
let _ = request::patch::<(), _>("recipe/set_difficulty", body).await;
});
}
})
@ -219,7 +219,7 @@ pub fn setup_page(recipe_id: i64) {
lang: language.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_language", body).await;
let _ = request::patch::<(), _>("recipe/set_language", body).await;
});
}
})
@ -235,7 +235,7 @@ pub fn setup_page(recipe_id: i64) {
is_published: is_published.checked(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_is_published", body).await;
let _ = request::patch::<(), _>("recipe/set_is_published", body).await;
reload_recipes_list(recipe_id).await;
});
})
@ -330,7 +330,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
.collect();
let body = ron_api::Ids { ids };
let _ = request::put::<(), _>("recipe/set_groups_order", body).await;
let _ = request::patch::<(), _>("recipe/set_groups_order", body).await;
});
});
@ -346,7 +346,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
name: name.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_group_name", body).await;
let _ = request::patch::<(), _>("recipe/set_group_name", body).await;
})
}
})
@ -364,7 +364,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
comment: comment.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_group_comment", body).await;
let _ = request::patch::<(), _>("recipe/set_group_comment", body).await;
});
}
})
@ -491,7 +491,7 @@ fn create_step_element(group_element: &Element, step: &ron_api::Step) -> Element
.collect();
let body = ron_api::Ids { ids };
let _ = request::put::<(), _>("recipe/set_steps_order", body).await;
let _ = request::patch::<(), _>("recipe/set_steps_order", body).await;
});
});
@ -507,7 +507,7 @@ fn create_step_element(group_element: &Element, step: &ron_api::Step) -> Element
action: action.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_step_action", body).await;
let _ = request::patch::<(), _>("recipe/set_step_action", body).await;
});
}
})
@ -583,7 +583,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
.collect();
let body = ron_api::Ids { ids };
let _ = request::put::<(), _>("recipe/set_ingredients_order", body).await;
let _ = request::patch::<(), _>("recipe/set_ingredients_order", body).await;
});
});
@ -599,7 +599,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
name: name.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_ingredient_name", body).await;
let _ = request::patch::<(), _>("recipe/set_ingredient_name", body).await;
});
}
})
@ -617,7 +617,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
comment: comment.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_ingredient_comment", body).await;
let _ = request::patch::<(), _>("recipe/set_ingredient_comment", body).await;
});
}
})
@ -644,7 +644,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
quantity: q,
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_ingredient_quantity", body).await;
let _ = request::patch::<(), _>("recipe/set_ingredient_quantity", body).await;
});
}
})
@ -662,7 +662,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
unit: unit.value(),
};
spawn_local(async move {
let _ = request::put::<(), _>("recipe/set_ingredient_unit", body).await;
let _ = request::patch::<(), _>("recipe/set_ingredient_unit", body).await;
});
}
})

View file

@ -1,6 +1,6 @@
use common::ron_api;
use gloo::net::http::{Request, RequestBuilder};
use serde::{de::DeserializeOwned, Serialize};
use serde::{Serialize, de::DeserializeOwned};
use thiserror::Error;
use crate::toast::{self, Level};
@ -90,6 +90,14 @@ where
req_with_body(api_name, body, Request::put).await
}
pub async fn patch<T, U>(api_name: &str, body: U) -> Result<T>
where
T: DeserializeOwned,
U: Serialize,
{
req_with_body(api_name, body, Request::patch).await
}
pub async fn post<T, U>(api_name: &str, body: U) -> Result<T>
where
T: DeserializeOwned,