use serde::{Deserialize, Serialize}; use serde_json::Value; use std::collections::HashMap; use crate::models::recipe::*; use crate::recipe_functions::common::*; /// Version 2 of `models::Recipe` /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct VersionRecipe { pub currentVersion: Value, pub knownVersions: Vec, pub recipesByCategory: HashMap>, } impl VersionRecipe { // import - read all file with given format from directory and mixing them together as 1 recipe pub fn create_versioning_by_country(country: &str) -> Self { let mut path = String::from(RECIPES_DIR); path.push_str(country); path.push('/'); // read dir let files = read_all_files_in_directory(&path.clone()); let expected_file_format = "coffeethai02"; let filtered = filter_files_by_pattern(files, expected_file_format); // create recipes vector let mut recipes = Vec::new(); let mut known_versions = Vec::new(); for file in filtered { // try create model let mut source_path = path.clone(); source_path.push_str(&file); let current_recipe_path = create_recipe_model_from_file(source_path); known_versions.push(current_recipe_path.clone().MachineSetting.configNumber); recipes.push(current_recipe_path.clone()); } // find current // let versions = grep_latest_versions(&path.clone()).unwrap(); let expected_version = versions.get(country).unwrap_or(&0); VersionRecipe { currentVersion: serde_json::json!(format!("{}", expected_version)), knownVersions: known_versions, recipesByCategory: break_down_recipe_into_category(recipes), } } // export // export_full // export_full_with_history } pub fn break_down_recipe_into_category(recipes: Vec) -> HashMap> { let mut result = HashMap::new(); // Steps // 1. result } /// Based on `models::Recipe`, this excluded some fields /// for more efficient serialization and deserialization. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct RecipeV2 { pub Description: Option, pub LastChange: Option, pub id: Value, pub isUse: bool, pub name: Option, pub otherName: Option, pub productCode: String, pub recipes: Vec, pub ToppingSet: Option>, pub total_time: Value, pub changeLog: Vec>, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct RecipeListWithHistory { pub recipeList: RecipeList, pub history: Vec>, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct MenuToppingListWithHistory { pub menuToppingList: MenuToppingList, pub history: Vec>, }