use cards, prevent negative servings
This commit is contained in:
parent
fc64df2b2a
commit
dd0ac1e4c7
3 changed files with 23 additions and 24 deletions
|
|
@ -75,7 +75,7 @@ async fn decrease(
|
|||
Path(id): Path<i32>
|
||||
) -> Redirect{
|
||||
let conn = conn.lock().unwrap();
|
||||
let mut stmt = conn.prepare("UPDATE food SET actual_servings = (SELECT actual_servings FROM food WHERE id = ?1) - 1 WHERE id = ?1").unwrap();
|
||||
let mut stmt = conn.prepare("UPDATE food SET actual_servings = MAX((SELECT actual_servings FROM food WHERE id = ?1) - 1, 0) WHERE id = ?1").unwrap();
|
||||
stmt.execute((id,)).unwrap();
|
||||
Redirect::to("/")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue