Adds ingredients managing

This commit is contained in:
2019-01-28 21:25:25 +01:00
parent 202d7c5976
commit 4576ffb03b
5 changed files with 42 additions and 33 deletions

View File

@@ -25,10 +25,18 @@ impl<'a> CreateRecipe<'a> {
self.title = title;
}
fn add_ingredient(&mut self, ingredient: String) {
// TODO: Validate ingredient
self.ingredients.push_str(&ingredient);
println!("+");
fn add_ingredient(&mut self, name: String) {
use crate::ingredients::*;
// Check it exists or create
if let Some(ingdt) = find(self.connection, &name) {
println!("=");
} else {
create(self.connection, &name);
println!("+{}", &name);
}
self.ingredients.push_str(&name);
}
fn insert(self) {