From b14e566593dd854783595ada4780fa0d5acef946 Mon Sep 17 00:00:00 2001 From: artus40 Date: Sun, 3 Feb 2019 21:12:48 +0100 Subject: [PATCH] makes models and schema modules privates, adds re-exports --- cookbook/db.sqlite3 | Bin 20480 -> 20480 bytes cookbook/src/bin/show_recipes.rs | 8 +++++--- cookbook/src/bin/write_recipe.rs | 7 ++++--- cookbook/src/lib.rs | 12 ++++++++---- planner/src/bin/weekly.rs | 2 +- web/src/main.rs | 2 +- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cookbook/db.sqlite3 b/cookbook/db.sqlite3 index fdbaf37f6ebd997c6972a7f24a298ca299a90b7b..26e15ee1f6795614dfd26ecd74e9228733e8055b 100644 GIT binary patch delta 156 zcmV;N0Av4vpaFoO0gxL3K9L+l0Y0%{q%Q~p57__@?ho0s5irdU6%zsm02=`p4N!G* z!>MHr0y7{qAT^WjKNcDV55xcu^AF??*bmPS#1F6!qYsx4iVt}YYO@g#Ob?T4Pg*<) z1p@#XLS=Pwa%Beu0{|6FVQF*<0|NjXP+@dobY*i50s{acLvn9*bZ>5R4GIeZ0{|UU KVQgV!Wep15%_`0S delta 151 zcmZozz}T>Wae_3X)kGO*MyrhpOZ3?o`QI_{zuPRRaEgCo05`upBO8M>ry*}}VoqX8 zD(~cX_F_^@{7)G8Kl4A~zsY}={{a66{>A*$`MdZl`Li|)3i$9(&hn44k#)(;OUcjU y<>F#tW{`HuPc2R3<>FyxW{~$uECNX|F*7JS7v-0h@n<(&'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,