add submenu

This commit is contained in:
pakintada@gmail.com 2024-01-23 16:23:38 +07:00
parent 9b0f111f5b
commit 84f18b6141
5 changed files with 91 additions and 19 deletions

View file

@ -186,6 +186,8 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
d.taoLogger.Log.Debug("invoke GetRecipe", zap.String("countryID", countryID), zap.String("filename", filename))
// TODO: concat submenu into recipe
if countryID == "" {
return d.currentRecipe["tha"]
}
@ -273,6 +275,12 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
for _, v := range d.currentRecipe[countryID].Recipe01 {
if v.ProductCode == productCode {
return v, nil
} else if len(v.SubMenu) > 0 {
for _, subMenu := range v.SubMenu {
if subMenu.ProductCode == productCode {
return subMenu, nil
}
}
}
}
fmt.Println("No result in current recipe", countryID)
@ -282,6 +290,13 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
if v.ProductCode == productCode {
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getSuccess", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
return v, nil
} else if len(v.SubMenu) > 0 {
for _, subMenu := range v.SubMenu {
if subMenu.ProductCode == productCode {
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getSuccess", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
return subMenu, nil
}
}
}
}
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getFail", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
@ -312,6 +327,12 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
for _, v := range d.currentRecipe[countryID].Recipe01 {
if v.ProductCode == productCode {
return v, fmt.Errorf("[DEFAULT]-ERR")
} else if len(v.SubMenu) > 0 {
for _, subMenu := range v.SubMenu {
if subMenu.ProductCode == productCode {
return subMenu, fmt.Errorf("[DEFAULT]-ERR")
}
}
}
}
}
@ -343,6 +364,13 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
if v.ProductCode == productCode {
// d.taoLogger.Log.Debug("GetRecipe01ByProductCode", zap.Any("productCode", productCode), zap.Any("result", v))
return v, nil
} else if len(v.SubMenu) > 0 {
for _, subMenu := range v.SubMenu {
if subMenu.ProductCode == productCode {
// d.taoLogger.Log.Debug("GetRecipe01ByProductCode", zap.Any("productCode", productCode), zap.Any("result", subMenu))
return subMenu, nil
}
}
}
}
@ -374,6 +402,26 @@ func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Re
not_found = false
break
} else if len(v.SubMenu) > 0 {
for _, sub := range v.SubMenu {
if sub.ProductCode == recipe.ProductCode {
// Log.Debug("SetValuesToRecipe.SubMenu", zap.Any("old", sub), zap.Any("new", recipe))
// sub = recipe
// TODO: change only changed values
// transform to map
base_recipe01_Map := sub.ToMap()
recipe01_Map := recipe.ToMap()
for k, v := range recipe01_Map {
if !reflect.DeepEqual(base_recipe01_Map[k], v) {
d.taoLogger.Log.Debug("SetValuesToRecipe.SubMenu", zap.Any("key", k), zap.Any("old", base_recipe01_Map[k]), zap.Any("new", v))
base_recipe01_Map[k] = v
}
}
}
}
} else {
not_found = true
global_idx = index

View file

@ -224,6 +224,17 @@ func (rs *recipeService) GetRecipeOverview(request *contracts.RecipeOverviewRequ
strings.Contains(strings.ToLower(v.OtherName), strings.ToLower(request.Search)) {
searchResult = append(searchResult, v)
}
// do seach submenu
if len(v.SubMenu) > 0 {
for _, sub := range v.SubMenu {
if strings.Contains(strings.ToLower(sub.ProductCode), strings.ToLower(request.Search)) ||
strings.Contains(strings.ToLower(sub.Name), strings.ToLower(request.Search)) ||
strings.Contains(strings.ToLower(sub.OtherName), strings.ToLower(request.Search)) {
searchResult = append(searchResult, sub)
// rs.taoLogger.Log.Debug("GetRecipeOverview.SubMenu", zap.Any("searchResult::GetSubMenu", sub))
}
}
}
}
recipeFilter = searchResult
}
@ -253,6 +264,22 @@ func (rs *recipeService) GetRecipeOverview(request *contracts.RecipeOverviewRequ
OtherDescription: v.OtherDescription,
LastUpdated: v.LastChange,
})
// submenu
if len(v.SubMenu) > 0 {
for _, sub := range v.SubMenu {
result.Result = append(result.Result, contracts.RecipeOverview{
ID: sub.ID,
ProductCode: sub.ProductCode,
Name: sub.Name,
OtherName: sub.OtherName,
Description: sub.Description,
OtherDescription: sub.OtherDescription,
LastUpdated: sub.LastChange,
})
}
}
}
result.TotalCount = len(result.Result)