makes models and schema modules privates, adds re-exports

This commit is contained in:
2019-02-03 21:12:48 +01:00
parent d3259c82b3
commit b14e566593
6 changed files with 19 additions and 12 deletions

Binary file not shown.

View File

@@ -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());
}
}

View File

@@ -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) => {

View File

@@ -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::*;

View File

@@ -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)

View File

@@ -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,