Replace PUT method by the more appropriate PATCH method.
This commit is contained in:
parent
8dcaac35b7
commit
9ed5a04e22
4 changed files with 46 additions and 37 deletions
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
* text=auto
|
||||||
|
|
@ -7,7 +7,7 @@ use axum::{
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
middleware::{self, Next},
|
middleware::{self, Next},
|
||||||
response::Response,
|
response::Response,
|
||||||
routing::{delete, get, post, put},
|
routing::{delete, get, patch, post, put},
|
||||||
};
|
};
|
||||||
use axum_extra::extract::cookie::CookieJar;
|
use axum_extra::extract::cookie::CookieJar;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
@ -113,33 +113,33 @@ async fn main() {
|
||||||
// .route("/user/update", put(services::ron::update_user))
|
// .route("/user/update", put(services::ron::update_user))
|
||||||
.route("/set_lang", put(services::ron::set_lang))
|
.route("/set_lang", put(services::ron::set_lang))
|
||||||
.route("/recipe/get_titles", get(services::ron::recipe::get_titles))
|
.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(
|
.route(
|
||||||
"/recipe/set_description",
|
"/recipe/set_description",
|
||||||
put(services::ron::recipe::set_description),
|
patch(services::ron::recipe::set_description),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_servings",
|
"/recipe/set_servings",
|
||||||
put(services::ron::recipe::set_servings),
|
patch(services::ron::recipe::set_servings),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_estimated_time",
|
"/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/get_tags", get(services::ron::recipe::get_tags))
|
||||||
.route("/recipe/add_tags", post(services::ron::recipe::add_tags))
|
.route("/recipe/add_tags", post(services::ron::recipe::add_tags))
|
||||||
.route("/recipe/rm_tags", delete(services::ron::recipe::rm_tags))
|
.route("/recipe/rm_tags", delete(services::ron::recipe::rm_tags))
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_difficulty",
|
"/recipe/set_difficulty",
|
||||||
put(services::ron::recipe::set_difficulty),
|
patch(services::ron::recipe::set_difficulty),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_language",
|
"/recipe/set_language",
|
||||||
put(services::ron::recipe::set_language),
|
patch(services::ron::recipe::set_language),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_is_published",
|
"/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/remove", delete(services::ron::recipe::rm))
|
||||||
.route("/recipe/get_groups", get(services::ron::recipe::get_groups))
|
.route("/recipe/get_groups", get(services::ron::recipe::get_groups))
|
||||||
|
|
@ -150,15 +150,15 @@ async fn main() {
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_group_name",
|
"/recipe/set_group_name",
|
||||||
put(services::ron::recipe::set_group_name),
|
patch(services::ron::recipe::set_group_name),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_group_comment",
|
"/recipe/set_group_comment",
|
||||||
put(services::ron::recipe::set_group_comment),
|
patch(services::ron::recipe::set_group_comment),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_groups_order",
|
"/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("/recipe/add_step", post(services::ron::recipe::add_step))
|
||||||
.route(
|
.route(
|
||||||
|
|
@ -167,11 +167,11 @@ async fn main() {
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_step_action",
|
"/recipe/set_step_action",
|
||||||
put(services::ron::recipe::set_step_action),
|
patch(services::ron::recipe::set_step_action),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_steps_order",
|
"/recipe/set_steps_order",
|
||||||
put(services::ron::recipe::set_steps_order),
|
patch(services::ron::recipe::set_steps_order),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/add_ingredient",
|
"/recipe/add_ingredient",
|
||||||
|
|
@ -183,23 +183,23 @@ async fn main() {
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_ingredient_name",
|
"/recipe/set_ingredient_name",
|
||||||
put(services::ron::recipe::set_ingredient_name),
|
patch(services::ron::recipe::set_ingredient_name),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_ingredient_comment",
|
"/recipe/set_ingredient_comment",
|
||||||
put(services::ron::recipe::set_ingredient_comment),
|
patch(services::ron::recipe::set_ingredient_comment),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_ingredient_quantity",
|
"/recipe/set_ingredient_quantity",
|
||||||
put(services::ron::recipe::set_ingredient_quantity),
|
patch(services::ron::recipe::set_ingredient_quantity),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_ingredient_unit",
|
"/recipe/set_ingredient_unit",
|
||||||
put(services::ron::recipe::set_ingredient_unit),
|
patch(services::ron::recipe::set_ingredient_unit),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/recipe/set_ingredients_order",
|
"/recipe/set_ingredients_order",
|
||||||
put(services::ron::recipe::set_ingredients_order),
|
patch(services::ron::recipe::set_ingredients_order),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/calendar/get_scheduled_recipes",
|
"/calendar/get_scheduled_recipes",
|
||||||
|
|
@ -219,7 +219,7 @@ async fn main() {
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/shopping_list/set_checked",
|
"/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);
|
.fallback(services::ron::not_found);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ pub fn setup_page(recipe_id: i64) {
|
||||||
title: title.value(),
|
title: title.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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;
|
reload_recipes_list(recipe_id).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +56,7 @@ pub fn setup_page(recipe_id: i64) {
|
||||||
description: description.value(),
|
description: description.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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,
|
servings,
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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,
|
estimated_time: time,
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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(),
|
.unwrap(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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(),
|
lang: language.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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(),
|
is_published: is_published.checked(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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;
|
reload_recipes_list(recipe_id).await;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
@ -330,7 +330,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let body = ron_api::Ids { ids };
|
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(),
|
name: name.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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(),
|
comment: comment.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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();
|
.collect();
|
||||||
|
|
||||||
let body = ron_api::Ids { ids };
|
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(),
|
action: action.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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();
|
.collect();
|
||||||
|
|
||||||
let body = ron_api::Ids { ids };
|
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(),
|
name: name.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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(),
|
comment: comment.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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,
|
quantity: q,
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
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(),
|
unit: unit.value(),
|
||||||
};
|
};
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let _ = request::put::<(), _>("recipe/set_ingredient_unit", body).await;
|
let _ = request::patch::<(), _>("recipe/set_ingredient_unit", body).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use common::ron_api;
|
use common::ron_api;
|
||||||
use gloo::net::http::{Request, RequestBuilder};
|
use gloo::net::http::{Request, RequestBuilder};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::toast::{self, Level};
|
use crate::toast::{self, Level};
|
||||||
|
|
@ -90,6 +90,14 @@ where
|
||||||
req_with_body(api_name, body, Request::put).await
|
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>
|
pub async fn post<T, U>(api_name: &str, body: U) -> Result<T>
|
||||||
where
|
where
|
||||||
T: DeserializeOwned,
|
T: DeserializeOwned,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue