pub async fn rm(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::Remove>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Id>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
- connection.rm_recipe(ron.recipe_id).await?;
+ check_user_rights_recipe(&connection, &user, ron.id).await?;
+ connection.rm_recipe(ron.id).await?;
Ok(StatusCode::OK)
}
pub async fn add_group(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::AddRecipeGroup>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Id>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
- let group_id = connection.add_recipe_group(ron.recipe_id).await?;
+ check_user_rights_recipe(&connection, &user, ron.id).await?;
+ let id = connection.add_recipe_group(ron.id).await?;
- Ok(ron_response(
- StatusCode::OK,
- common::ron_api::AddRecipeGroupResult { group_id },
- ))
+ Ok(ron_response(StatusCode::OK, common::ron_api::Id { id }))
}
#[debug_handler]
pub async fn rm_group(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::RemoveRecipeGroup>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Id>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_group(&connection, &user, ron.group_id).await?;
- connection.rm_recipe_group(ron.group_id).await?;
+ check_user_rights_recipe_group(&connection, &user, ron.id).await?;
+ connection.rm_recipe_group(ron.id).await?;
Ok(StatusCode::OK)
}
pub async fn set_groups_order(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::SetGroupOrders>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Ids>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_groups(&connection, &user, &ron.group_ids).await?;
- connection.set_groups_order(&ron.group_ids).await?;
+ check_user_rights_recipe_groups(&connection, &user, &ron.ids).await?;
+ connection.set_groups_order(&ron.ids).await?;
Ok(StatusCode::OK)
}
pub async fn add_step(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::AddRecipeStep>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Id>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_group(&connection, &user, ron.group_id).await?;
- let step_id = connection.add_recipe_step(ron.group_id).await?;
+ check_user_rights_recipe_group(&connection, &user, ron.id).await?;
+ let id = connection.add_recipe_step(ron.id).await?;
- Ok(ron_response(
- StatusCode::OK,
- common::ron_api::AddRecipeStepResult { step_id },
- ))
+ Ok(ron_response(StatusCode::OK, common::ron_api::Id { id }))
}
#[debug_handler]
pub async fn rm_step(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::RemoveRecipeStep>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Id>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_step(&connection, &user, ron.step_id).await?;
- connection.rm_recipe_step(ron.step_id).await?;
+ check_user_rights_recipe_step(&connection, &user, ron.id).await?;
+ connection.rm_recipe_step(ron.id).await?;
Ok(StatusCode::OK)
}
pub async fn set_steps_order(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::SetStepOrders>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Ids>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_steps(&connection, &user, &ron.step_ids).await?;
- connection.set_steps_order(&ron.step_ids).await?;
+ check_user_rights_recipe_steps(&connection, &user, &ron.ids).await?;
+ connection.set_steps_order(&ron.ids).await?;
Ok(StatusCode::OK)
}
pub async fn add_ingredient(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::AddRecipeIngredient>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Id>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_step(&connection, &user, ron.step_id).await?;
- let ingredient_id = connection.add_recipe_ingredient(ron.step_id).await?;
+ check_user_rights_recipe_step(&connection, &user, ron.id).await?;
+ let id = connection.add_recipe_ingredient(ron.id).await?;
- Ok(ron_response(
- StatusCode::OK,
- common::ron_api::AddRecipeIngredientResult { ingredient_id },
- ))
+ Ok(ron_response(StatusCode::OK, common::ron_api::Id { id }))
}
#[debug_handler]
pub async fn rm_ingredient(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::RemoveRecipeIngredient>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Id>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_ingredient(&connection, &user, ron.ingredient_id).await?;
- connection.rm_recipe_ingredient(ron.ingredient_id).await?;
+ check_user_rights_recipe_ingredient(&connection, &user, ron.id).await?;
+ connection.rm_recipe_ingredient(ron.id).await?;
Ok(StatusCode::OK)
}
pub async fn set_ingredients_order(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
- ExtractRon(ron): ExtractRon<common::ron_api::SetIngredientOrders>,
+ ExtractRon(ron): ExtractRon<common::ron_api::Ids>,
) -> Result<impl IntoResponse> {
- check_user_rights_recipe_ingredients(&connection, &user, &ron.ingredient_ids).await?;
- connection
- .set_ingredients_order(&ron.ingredient_ids)
- .await?;
+ check_user_rights_recipe_ingredients(&connection, &user, &ron.ids).await?;
+ connection.set_ingredients_order(&ron.ids).await?;
Ok(StatusCode::OK)
}
pub lang: String,
}
+#[derive(Serialize, Deserialize, Clone)]
+pub struct Ids {
+ pub ids: Vec<i64>,
+}
+
+#[derive(Serialize, Deserialize, Clone)]
+pub struct Id {
+ pub id: i64,
+}
+
///// RECIPE /////
#[derive(Serialize, Deserialize, Clone)]
pub is_published: bool,
}
-#[derive(Serialize, Deserialize, Clone)]
-pub struct Remove {
- pub recipe_id: i64,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddRecipeGroup {
- pub recipe_id: i64,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddRecipeGroupResult {
- pub group_id: i64,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct RemoveRecipeGroup {
- pub group_id: i64,
-}
-
#[derive(Serialize, Deserialize, Clone)]
pub struct SetGroupName {
pub group_id: i64,
pub comment: String,
}
-#[derive(Serialize, Deserialize, Clone)]
-pub struct SetGroupOrders {
- pub group_ids: Vec<i64>,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddRecipeStep {
- pub group_id: i64,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddRecipeStepResult {
- pub step_id: i64,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct RemoveRecipeStep {
- pub step_id: i64,
-}
-
#[derive(Serialize, Deserialize, Clone)]
pub struct SetStepAction {
pub step_id: i64,
pub action: String,
}
-#[derive(Serialize, Deserialize, Clone)]
-pub struct SetStepOrders {
- pub step_ids: Vec<i64>,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddRecipeIngredient {
- pub step_id: i64,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct AddRecipeIngredientResult {
- pub ingredient_id: i64,
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct RemoveRecipeIngredient {
- pub ingredient_id: i64,
-}
-
#[derive(Serialize, Deserialize, Clone)]
pub struct SetIngredientName {
pub ingredient_id: i64,
pub unit: String,
}
-#[derive(Serialize, Deserialize, Clone)]
-pub struct SetIngredientOrders {
- pub ingredient_ids: Vec<i64>,
-}
-
#[derive(Serialize, Deserialize, Clone)]
pub struct Tags {
pub recipe_id: i64,
pub quantity_unit: String,
}
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeImage {
-// pub recipe_id: i64,
-// pub image: Vec<u8>,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeImageReply {
-// pub image_id: i64,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct RemoveRecipeImage {
-// pub image_id: i64,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeIngredient {
-// pub group_id: i64,
-// pub name: String,
-// pub quantity_value: Option<f64>,
-// pub quantity_unit: String,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeIngredientReply {
-// pub ingredient_id: i64,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct RemoveRecipeIngredient {
-// pub group_id: i64,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct SetRecipeIngredientsOrder {
-// pub group_id: i64,
-// pub ingredient_ids: Vec<i64>,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeGroup {
-// pub recipe_id: i64,
-// pub name: String,
-// pub quantity_value: Option<f64>,
-// pub quantity_unit: String,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeGroupReply {
-// pub group_id: i64,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct RemoveRecipeGroupReply {
-// pub group_id: i64,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct SetRecipeGroupsOrder {
-// pub recipe_id: i64,
-// pub group_ids: Vec<i64>,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeStep {
-// pub group_id: i64,
-// pub name: String,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct AddRecipeStepReply {
-// pub step_id: i64,
-// }
-
-// #[derive(Serialize, Deserialize, Clone)]
-// pub struct RemoveRecipeStep {
-// pub step_id: i64,
-// }
-
///// PROFILE /////
#[derive(Serialize, Deserialize, Clone)]
))
.await
{
- let body = ron_api::Remove { recipe_id };
+ let body = ron_api::Id { id: recipe_id };
let _ = request::delete::<(), _>("recipe/remove", body).await;
window().location().set_href("/").unwrap();
{
let button_add_group: HtmlInputElement = by_id("input-add-group");
let on_click_add_group = EventListener::new(&button_add_group, "click", move |_event| {
- let body = ron_api::AddRecipeGroup { recipe_id };
+ let body = ron_api::Id { id: recipe_id };
spawn_local(async move {
- let response: ron_api::AddRecipeGroupResult =
- request::post("recipe/add_group", body).await.unwrap();
+ let response: ron_api::Id = request::post("recipe/add_group", body).await.unwrap();
create_group_element(&ron_api::Group {
- id: response.group_id,
+ id: response.id,
name: "".to_string(),
comment: "".to_string(),
steps: vec![],
set_draggable(&group_element, "group", |_element| {
spawn_local(async move {
- let group_ids = by_id::<Element>("groups-container")
+ let ids = by_id::<Element>("groups-container")
.selector_all::<Element>(".group")
.into_iter()
.map(|e| e.id()[6..].parse::<i64>().unwrap())
.collect();
- let body = ron_api::SetGroupOrders { group_ids };
+ let body = ron_api::Ids { ids };
let _ = request::put::<(), _>("recipe/set_groups_order", body).await;
});
});
.value();
spawn_local(async move {
if modal_dialog::show(&format!("Are you sure to delete the group '{}'", name)).await {
- let body = ron_api::RemoveRecipeGroup { group_id };
+ let body = ron_api::Id { id: group_id };
let _ = request::delete::<(), _>("recipe/remove_group", body).await;
let group_element = by_id::<Element>(&format!("group-{}", group_id));
group_element.next_element_sibling().unwrap().remove();
let add_step_button: HtmlInputElement = group_element.selector(".input-add-step");
EventListener::new(&add_step_button, "click", move |_event| {
spawn_local(async move {
- let body = ron_api::AddRecipeStep { group_id };
- let response: ron_api::AddRecipeStepResult =
- request::post("recipe/add_step", body).await.unwrap();
+ let body = ron_api::Id { id: group_id };
+ let response: ron_api::Id = request::post("recipe/add_step", body).await.unwrap();
create_step_element(
&selector::<Element>(&format!("#group-{} .steps", group_id)),
&ron_api::Step {
- id: response.step_id,
+ id: response.id,
action: "".to_string(),
ingredients: vec![],
},
set_draggable(&step_element, "step", |element| {
let element = element.clone();
spawn_local(async move {
- let step_ids = element
+ let ids = element
.parent_element()
.unwrap()
.selector_all::<Element>(".step")
.map(|e| e.id()[5..].parse::<i64>().unwrap())
.collect();
- let body = ron_api::SetStepOrders { step_ids };
+ let body = ron_api::Ids { ids };
let _ = request::put::<(), _>("recipe/set_steps_order", body).await;
});
});
.value();
spawn_local(async move {
if modal_dialog::show(&format!("Are you sure to delete the step '{}'", action)).await {
- let body = ron_api::RemoveRecipeStep { step_id };
+ let body = ron_api::Id { id: step_id };
let _ = request::delete::<(), _>("recipe/remove_step", body).await;
let step_element = by_id::<Element>(&format!("step-{}", step_id));
step_element.next_element_sibling().unwrap().remove();
let add_ingredient_button: HtmlInputElement = step_element.selector(".input-add-ingredient");
EventListener::new(&add_ingredient_button, "click", move |_event| {
spawn_local(async move {
- let body = ron_api::AddRecipeIngredient { step_id };
- let response: ron_api::AddRecipeIngredientResult =
- request::post("recipe/add_ingredient", body).await.unwrap();
+ let body = ron_api::Id { id: step_id };
+ let response: ron_api::Id = request::post("recipe/add_ingredient", body).await.unwrap();
create_ingredient_element(
&selector::<Element>(&format!("#step-{} .ingredients", step_id)),
&ron_api::Ingredient {
- id: response.ingredient_id,
+ id: response.id,
name: "".to_string(),
comment: "".to_string(),
quantity_value: None,
set_draggable(&ingredient_element, "ingredient", |element| {
let element = element.clone();
spawn_local(async move {
- let ingredient_ids = element
+ let ids = element
.parent_element()
.unwrap()
.selector_all::<Element>(".ingredient")
.map(|e| e.id()[11..].parse::<i64>().unwrap())
.collect();
- let body = ron_api::SetIngredientOrders { ingredient_ids };
+ let body = ron_api::Ids { ids };
let _ = request::put::<(), _>("recipe/set_ingredients_order", body).await;
});
});
if modal_dialog::show(&format!("Are you sure to delete the ingredient '{}'", name))
.await
{
- let body = ron_api::RemoveRecipeIngredient { ingredient_id };
+ let body = ron_api::Id { id: ingredient_id };
let _ = request::delete::<(), _>("recipe/remove_ingredient", body).await;
by_id::<Element>(&format!("ingredient-{}", ingredient_id)).remove();
}