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())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue