Steps can now be ordered (via drag and drop)
This commit is contained in:
parent
e355800f98
commit
b86cded45d
8 changed files with 316 additions and 112 deletions
|
|
@ -507,12 +507,14 @@ ORDER BY [name]
|
|||
.await?
|
||||
.unwrap_or(-1);
|
||||
|
||||
let db_result = sqlx::query("INSERT INTO [Group] ([recipe_id, [order]) VALUES ($1, $2)")
|
||||
let db_result = sqlx::query("INSERT INTO [Group] ([recipe_id], [order]) VALUES ($1, $2)")
|
||||
.bind(recipe_id)
|
||||
.bind(last_order + 1)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
Ok(db_result.last_insert_rowid())
|
||||
}
|
||||
|
||||
|
|
@ -562,10 +564,24 @@ ORDER BY [name]
|
|||
}
|
||||
|
||||
pub async fn add_recipe_step(&self, group_id: i64) -> Result<i64> {
|
||||
let db_result = sqlx::query("INSERT INTO [Step] ([group_id]) VALUES ($1)")
|
||||
let mut tx = self.tx().await?;
|
||||
|
||||
let last_order = sqlx::query_scalar(
|
||||
"SELECT [order] FROM [Step] WHERE [group_id] = $1 ORDER BY [order] DESC LIMIT 1",
|
||||
)
|
||||
.bind(group_id)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
.unwrap_or(-1);
|
||||
|
||||
let db_result = sqlx::query("INSERT INTO [Step] ([group_id], [order]) VALUES ($1, $2)")
|
||||
.bind(group_id)
|
||||
.execute(&self.pool)
|
||||
.bind(last_order + 1)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
Ok(db_result.last_insert_rowid())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ async fn main() {
|
|||
)
|
||||
.route(
|
||||
"/recipe/set_groups_order",
|
||||
put(services::ron::set_group_orders),
|
||||
put(services::ron::set_groups_order),
|
||||
)
|
||||
.route("/recipe/add_step", post(services::ron::add_step))
|
||||
.route("/recipe/remove_step", delete(services::ron::rm_step))
|
||||
|
|
@ -145,6 +145,10 @@ async fn main() {
|
|||
"/recipe/set_step_action",
|
||||
put(services::ron::set_step_action),
|
||||
)
|
||||
.route(
|
||||
"/recipe/set_steps_order",
|
||||
put(services::ron::set_steps_order),
|
||||
)
|
||||
.route(
|
||||
"/recipe/add_ingredient",
|
||||
post(services::ron::add_ingredient),
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ pub async fn set_group_comment(
|
|||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn set_group_orders(
|
||||
pub async fn set_groups_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::SetGroupOrders>,
|
||||
|
|
@ -483,7 +483,7 @@ pub async fn set_step_action(
|
|||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn set_step_orders(
|
||||
pub async fn set_steps_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::SetStepOrders>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue