diff --git a/cookbook/db.sqlite3 b/cookbook/db.sqlite3 index fdbaf37..26e15ee 100644 Binary files a/cookbook/db.sqlite3 and b/cookbook/db.sqlite3 differ diff --git a/cookbook/src/bin/show_recipes.rs b/cookbook/src/bin/show_recipes.rs index f92dae1..9926e4e 100644 --- a/cookbook/src/bin/show_recipes.rs +++ b/cookbook/src/bin/show_recipes.rs @@ -2,10 +2,12 @@ extern crate cookbook; extern crate diesel; use self::cookbook::*; -use self::models::*; use diesel::sqlite::SqliteConnection; -use cookbook::models::fields::IngredientList; +use cookbook::{ + ingredients::IngredientList, + recipes::Recipe, +}; struct IngredientListManager<'a>(&'a SqliteConnection, IngredientList); @@ -28,6 +30,6 @@ fn main() { for rec in result { println!("*************\n{}\n({:?})", rec.title, rec.category); println!("-------------\n"); - println!("{}", rec.ingredients.as_string()); + println!("{}", IngredientListManager(&conn, rec.ingredients).display_lines()); } } diff --git a/cookbook/src/bin/write_recipe.rs b/cookbook/src/bin/write_recipe.rs index 694a062..61d82fa 100644 --- a/cookbook/src/bin/write_recipe.rs +++ b/cookbook/src/bin/write_recipe.rs @@ -3,8 +3,9 @@ extern crate diesel; use std::io::{stdin}; use diesel::SqliteConnection; -use self::cookbook::*; -use self::models::{NewRecipe, fields::RecipeCategory, fields::IngredientList}; +use cookbook::*; +use cookbook::recipes::{NewRecipe, RecipeCategory}; +use cookbook::ingredients::{IngredientList}; struct CreateRecipe<'a> { connection: &'a SqliteConnection, @@ -33,7 +34,7 @@ impl<'a> CreateRecipe<'a> { fn add_ingredient(&mut self, name: String) { use crate::ingredients::*; - + let name = name.trim(); // Check it exists or create match get_id_or_create(self.connection, &name) { Ok(id) => { diff --git a/cookbook/src/lib.rs b/cookbook/src/lib.rs index 1079a44..60c84f7 100644 --- a/cookbook/src/lib.rs +++ b/cookbook/src/lib.rs @@ -2,8 +2,8 @@ extern crate diesel; extern crate dotenv; -pub mod schema; -pub mod models; +mod schema; +mod models; mod importer; @@ -20,7 +20,7 @@ pub fn establish_connection() -> SqliteConnection { } pub mod recipes { - use crate::models::{Recipe}; + pub use crate::models::{Recipe, NewRecipe, fields::RecipeCategory}; use super::{SqliteConnection, schema}; use super::diesel::prelude::*; @@ -41,7 +41,11 @@ pub mod recipes { } pub mod ingredients { - use crate::models::{Ingredient, NewIngredient, fields::IngredientId}; + pub use crate::models::{ + Ingredient, + NewIngredient, + fields::{IngredientId, IngredientList}, + }; use super::{SqliteConnection, schema}; use super::diesel::prelude::*; diff --git a/planner/src/bin/weekly.rs b/planner/src/bin/weekly.rs index 79a5045..9282959 100644 --- a/planner/src/bin/weekly.rs +++ b/planner/src/bin/weekly.rs @@ -4,7 +4,7 @@ extern crate cookbook; extern crate planner; use self::cookbook::*; -use self::cookbook::models::Recipe; +use self::cookbook::recipes::Recipe; use self::planner::solver::{Variables, Domain, Problem}; /// We want a mapping of the week meals (matin, midi, soir) diff --git a/web/src/main.rs b/web/src/main.rs index 302f46e..3bf8178 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -35,7 +35,7 @@ mod api { } impl Recipe { - fn from(rec: models::Recipe) -> Recipe { + fn from(rec: recipes::Recipe) -> Recipe { Recipe { id: rec.id, title: rec.title,