Recipe edit (WIP): Buttons to add steps and inrgedients
This commit is contained in:
parent
6876a254e1
commit
d4962c98ff
9 changed files with 182 additions and 15 deletions
|
|
@ -304,6 +304,23 @@ ORDER BY [name]
|
|||
.map_err(DBError::from)
|
||||
}
|
||||
|
||||
pub async fn add_recipe_step(&self, group_id: i64) -> Result<i64> {
|
||||
let db_result = sqlx::query("INSERT INTO [Step] ([group_id]) VALUES ($1)")
|
||||
.bind(group_id)
|
||||
.execute(&self.pool)
|
||||
.await?;
|
||||
Ok(db_result.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub async fn rm_recipe_step(&self, step_id: i64) -> Result<()> {
|
||||
sqlx::query("DELETE FROM [Step] WHERE [id] = $1")
|
||||
.bind(step_id)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(DBError::from)
|
||||
}
|
||||
|
||||
pub async fn set_step_action(&self, step_id: i64, action: &str) -> Result<()> {
|
||||
sqlx::query("UPDATE [Step] SET [action] = $2 WHERE [id] = $1")
|
||||
.bind(step_id)
|
||||
|
|
@ -314,6 +331,23 @@ ORDER BY [name]
|
|||
.map_err(DBError::from)
|
||||
}
|
||||
|
||||
pub async fn add_recipe_ingredient(&self, step_id: i64) -> Result<i64> {
|
||||
let db_result = sqlx::query("INSERT INTO [Ingredient] ([step_id]) VALUES ($1)")
|
||||
.bind(step_id)
|
||||
.execute(&self.pool)
|
||||
.await?;
|
||||
Ok(db_result.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub async fn rm_recipe_ingredient(&self, ingredient_id: i64) -> Result<()> {
|
||||
sqlx::query("DELETE FROM [Ingredient] WHERE [id] = $1")
|
||||
.bind(ingredient_id)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(DBError::from)
|
||||
}
|
||||
|
||||
pub async fn set_ingredient_name(&self, ingredient_id: i64, name: &str) -> Result<()> {
|
||||
sqlx::query("UPDATE [Ingredient] SET [name] = $2 WHERE [id] = $1")
|
||||
.bind(ingredient_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue