55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
use crate::domain::ingredient::types;
|
|
|
|
pub trait IngredientRepo {
|
|
fn get_ingredients(&self) -> Vec<types::Ingredient>;
|
|
}
|
|
|
|
pub struct StaticIngredientRepo {}
|
|
|
|
impl IngredientRepo for StaticIngredientRepo {
|
|
fn get_ingredients(&self) -> Vec<types::Ingredient> {
|
|
db::INGREDIENTS.iter().map(From::from).collect::<Vec<_>>()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
pub struct InMemoryIngredientRepo {
|
|
pub ingredients: Vec<db::data::Ingredient>,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
impl InMemoryIngredientRepo {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
ingredients: vec![
|
|
db::data::Ingredient {
|
|
key: "apple",
|
|
translates: db::data::IngredientTranslate {
|
|
ru: "Яблоко",
|
|
en: Some("Apple"),
|
|
},
|
|
},
|
|
db::data::Ingredient {
|
|
key: "salt",
|
|
translates: db::data::IngredientTranslate {
|
|
ru: "Соль",
|
|
en: Some("Salt"),
|
|
},
|
|
},
|
|
],
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
impl IngredientRepo for InMemoryIngredientRepo {
|
|
fn get_ingredients(&self) -> Vec<types::Ingredient> {
|
|
let langs = [types::Lang::Rus].repeat(self.ingredients.len());
|
|
self.ingredients
|
|
.iter()
|
|
.zip(langs)
|
|
.map(From::from)
|
|
.collect::<Vec<_>>()
|
|
}
|
|
}
|