131 lines
5.9 KiB
Rust
131 lines
5.9 KiB
Rust
use crate::domain::{misc_types::Lang, recipe::types};
|
||
|
||
use super::ingredient::IngredientRepo;
|
||
|
||
pub trait RecipeRepo {
|
||
fn get_recipes(&self) -> Vec<types::Recipe>;
|
||
}
|
||
|
||
pub struct StaticRecipeRepo;
|
||
|
||
impl RecipeRepo for StaticRecipeRepo {
|
||
fn get_recipes(&self) -> Vec<types::Recipe> {
|
||
let ings_repo = crate::repo::ingredient::StaticIngredientRepo;
|
||
let ings = ings_repo.get_ingredients(Default::default());
|
||
|
||
let langs = [Lang::default()].repeat(db::RECIPES.len());
|
||
db::RECIPES
|
||
.iter()
|
||
.zip(langs)
|
||
.map(|(rec, lang)| From::from((rec, lang, ings.clone())))
|
||
.collect()
|
||
}
|
||
}
|
||
|
||
#[cfg(test)]
|
||
pub struct InMemoryRecipeRepo {
|
||
recipes: Vec<db::data::Recipe>,
|
||
}
|
||
|
||
#[cfg(test)]
|
||
impl InMemoryRecipeRepo {
|
||
pub fn new() -> Self {
|
||
use db::data as Db;
|
||
use Db::RecipeIngredientMeasure as DbRIM;
|
||
|
||
Self {
|
||
recipes: vec![
|
||
Db::Recipe {
|
||
key: "fruit_salad",
|
||
steps: 0,
|
||
ingredients: vec![
|
||
Db::RecipeIngredient {
|
||
key: "banana",
|
||
measure: DbRIM::Gram(150),
|
||
},
|
||
Db::RecipeIngredient {
|
||
key: "apple",
|
||
measure: DbRIM::Gram(150),
|
||
},
|
||
Db::RecipeIngredient {
|
||
key: "orange",
|
||
measure: DbRIM::Gram(150),
|
||
},
|
||
],
|
||
translates: Db::RecipeTranslates {
|
||
rus: Db::RecipeTranslate {
|
||
name: "Фруктовый салат",
|
||
instructions: vec![
|
||
"Нарезать бананы кружочками",
|
||
"Нарезать яблоки и апельсины кубиками",
|
||
"Все ингредиенты перемешать",
|
||
],
|
||
},
|
||
eng: None,
|
||
},
|
||
},
|
||
Db::Recipe {
|
||
key: "thin_crispy_pizza_base",
|
||
steps: 7,
|
||
ingredients: vec![
|
||
Db::RecipeIngredient {
|
||
key: "salt",
|
||
measure: DbRIM::Gram(5),
|
||
},
|
||
Db::RecipeIngredient {
|
||
key: "sugar",
|
||
measure: DbRIM::Gram(4),
|
||
},
|
||
Db::RecipeIngredient {
|
||
key: "wheat_flour",
|
||
measure: DbRIM::Gram(500),
|
||
},
|
||
Db::RecipeIngredient {
|
||
key: "dry_yeast",
|
||
measure: DbRIM::Gram(7),
|
||
},
|
||
Db::RecipeIngredient {
|
||
key: "olive_oil",
|
||
measure: DbRIM::MilliLiter(25),
|
||
},
|
||
Db::RecipeIngredient {
|
||
key: "water",
|
||
measure: DbRIM::MilliLiter(250),
|
||
},
|
||
],
|
||
translates: Db::RecipeTranslates {
|
||
rus: Db::RecipeTranslate {
|
||
name: "Тонкая хрустящая основа для пиццы",
|
||
instructions: vec![
|
||
"Растворить дрожжи в воде, подогретой до температуры тела.",
|
||
"Добавить соль, сахар, оливковое масло и хорошо перемешать до однородной консистенции.",
|
||
"Добавить муку и замесить тесто. Вымешивать не менее 15 минут.",
|
||
"Разделить тесто на 3 порции, каждую завернуть в пищевую плёнку и дать настояться около 30 минут.",
|
||
"Растянуть один кусок теста до тонкого состояния и аккуратно переложить на смазанный растительным маслом противень.",
|
||
"Смазать соусом, чтобы тесто не осталось жидким и чтобы начинка не скользила по нему, и поставить в предварительно разогретую до максимальной температуры (не меньше 250 градусов) на 5-10 минут. В результате тесто хорошо пропечется и станет хрустящим.",
|
||
"Теперь на основу можно выкладывать начинку на ваш вкус и запекать до момента, когда сыр растает.",
|
||
],
|
||
},
|
||
eng: None,
|
||
},
|
||
},
|
||
],
|
||
}
|
||
}
|
||
}
|
||
|
||
#[cfg(test)]
|
||
impl RecipeRepo for InMemoryRecipeRepo {
|
||
fn get_recipes(&self) -> Vec<types::Recipe> {
|
||
let ings_repo = crate::repo::ingredient::InMemoryIngredientRepo::new();
|
||
let ings = ings_repo.get_ingredients(Default::default());
|
||
|
||
let langs = [Lang::default()].repeat(self.recipes.len());
|
||
self.recipes
|
||
.iter()
|
||
.zip(langs)
|
||
.map(|(rec, lang)| From::from((rec, lang, ings.clone())))
|
||
.collect()
|
||
}
|
||
}
|