v0.1 init
This commit is contained in:
commit
8068810af6
18 changed files with 3859 additions and 0 deletions
93
src/models/recipev2.rs
Normal file
93
src/models/recipev2.rs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
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<Value>,
|
||||
pub recipesByCategory: HashMap<String, Vec<RecipeV2>>,
|
||||
}
|
||||
|
||||
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<Recipe>) -> HashMap<String, Vec<RecipeV2>> {
|
||||
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<String>,
|
||||
pub LastChange: Option<Value>,
|
||||
pub id: Value,
|
||||
pub isUse: bool,
|
||||
pub name: Option<String>,
|
||||
pub otherName: Option<String>,
|
||||
pub productCode: String,
|
||||
pub recipes: Vec<RecipeListWithHistory>,
|
||||
pub ToppingSet: Option<Vec<MenuToppingListWithHistory>>,
|
||||
pub total_time: Value,
|
||||
pub changeLog: Vec<HashMap<String, Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct RecipeListWithHistory {
|
||||
pub recipeList: RecipeList,
|
||||
pub history: Vec<HashMap<String, Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct MenuToppingListWithHistory {
|
||||
pub menuToppingList: MenuToppingList,
|
||||
pub history: Vec<HashMap<String, Value>>,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue