use crate::domain::ingredient::types; pub trait IngredientRepo { fn get_ingredients(&self) -> Vec; } pub struct StaticIngredientRepo {} impl IngredientRepo for StaticIngredientRepo { fn get_ingredients(&self) -> Vec { db::INGREDIENTS.iter().map(From::from).collect::>() } } #[cfg(test)] pub struct InMemoryIngredientRepo { pub ingredients: Vec, } #[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 { let langs = [types::Lang::Rus].repeat(self.ingredients.len()); self.ingredients .iter() .zip(langs) .map(From::from) .collect::>() } }