From 9ed5a04e224394ba3f9b82abef0fbb8edfacddb8 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Tue, 18 Mar 2025 20:02:30 +0100 Subject: [PATCH] Replace PUT method by the more appropriate PATCH method. --- .gitattributes | 1 + backend/src/main.rs | 38 ++++++++++++++++++------------------- frontend/src/recipe_edit.rs | 34 ++++++++++++++++----------------- frontend/src/request.rs | 10 +++++++++- 4 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2125666 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/backend/src/main.rs b/backend/src/main.rs index afc7656..efee562 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -7,7 +7,7 @@ use axum::{ http::StatusCode, middleware::{self, Next}, response::Response, - routing::{delete, get, post, put}, + routing::{delete, get, patch, post, put}, }; use axum_extra::extract::cookie::CookieJar; use chrono::prelude::*; @@ -113,33 +113,33 @@ async fn main() { // .route("/user/update", put(services::ron::update_user)) .route("/set_lang", put(services::ron::set_lang)) .route("/recipe/get_titles", get(services::ron::recipe::get_titles)) - .route("/recipe/set_title", put(services::ron::recipe::set_title)) + .route("/recipe/set_title", patch(services::ron::recipe::set_title)) .route( "/recipe/set_description", - put(services::ron::recipe::set_description), + patch(services::ron::recipe::set_description), ) .route( "/recipe/set_servings", - put(services::ron::recipe::set_servings), + patch(services::ron::recipe::set_servings), ) .route( "/recipe/set_estimated_time", - put(services::ron::recipe::set_estimated_time), + patch(services::ron::recipe::set_estimated_time), ) .route("/recipe/get_tags", get(services::ron::recipe::get_tags)) .route("/recipe/add_tags", post(services::ron::recipe::add_tags)) .route("/recipe/rm_tags", delete(services::ron::recipe::rm_tags)) .route( "/recipe/set_difficulty", - put(services::ron::recipe::set_difficulty), + patch(services::ron::recipe::set_difficulty), ) .route( "/recipe/set_language", - put(services::ron::recipe::set_language), + patch(services::ron::recipe::set_language), ) .route( "/recipe/set_is_published", - put(services::ron::recipe::set_is_published), + patch(services::ron::recipe::set_is_published), ) .route("/recipe/remove", delete(services::ron::recipe::rm)) .route("/recipe/get_groups", get(services::ron::recipe::get_groups)) @@ -150,15 +150,15 @@ async fn main() { ) .route( "/recipe/set_group_name", - put(services::ron::recipe::set_group_name), + patch(services::ron::recipe::set_group_name), ) .route( "/recipe/set_group_comment", - put(services::ron::recipe::set_group_comment), + patch(services::ron::recipe::set_group_comment), ) .route( "/recipe/set_groups_order", - put(services::ron::recipe::set_groups_order), + patch(services::ron::recipe::set_groups_order), ) .route("/recipe/add_step", post(services::ron::recipe::add_step)) .route( @@ -167,11 +167,11 @@ async fn main() { ) .route( "/recipe/set_step_action", - put(services::ron::recipe::set_step_action), + patch(services::ron::recipe::set_step_action), ) .route( "/recipe/set_steps_order", - put(services::ron::recipe::set_steps_order), + patch(services::ron::recipe::set_steps_order), ) .route( "/recipe/add_ingredient", @@ -183,23 +183,23 @@ async fn main() { ) .route( "/recipe/set_ingredient_name", - put(services::ron::recipe::set_ingredient_name), + patch(services::ron::recipe::set_ingredient_name), ) .route( "/recipe/set_ingredient_comment", - put(services::ron::recipe::set_ingredient_comment), + patch(services::ron::recipe::set_ingredient_comment), ) .route( "/recipe/set_ingredient_quantity", - put(services::ron::recipe::set_ingredient_quantity), + patch(services::ron::recipe::set_ingredient_quantity), ) .route( "/recipe/set_ingredient_unit", - put(services::ron::recipe::set_ingredient_unit), + patch(services::ron::recipe::set_ingredient_unit), ) .route( "/recipe/set_ingredients_order", - put(services::ron::recipe::set_ingredients_order), + patch(services::ron::recipe::set_ingredients_order), ) .route( "/calendar/get_scheduled_recipes", @@ -219,7 +219,7 @@ async fn main() { ) .route( "/shopping_list/set_checked", - put(services::ron::shopping_list::set_entry_checked), + patch(services::ron::shopping_list::set_entry_checked), ) .fallback(services::ron::not_found); diff --git a/frontend/src/recipe_edit.rs b/frontend/src/recipe_edit.rs index 575a73a..9fbf10e 100644 --- a/frontend/src/recipe_edit.rs +++ b/frontend/src/recipe_edit.rs @@ -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; }); } }) diff --git a/frontend/src/request.rs b/frontend/src/request.rs index 26a98b4..0e1ef31 100644 --- a/frontend/src/request.rs +++ b/frontend/src/request.rs @@ -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(api_name: &str, body: U) -> Result +where + T: DeserializeOwned, + U: Serialize, +{ + req_with_body(api_name, body, Request::patch).await +} + pub async fn post(api_name: &str, body: U) -> Result where T: DeserializeOwned, -- 2.49.0