fix country params
This commit is contained in:
parent
4ece2cf30c
commit
09d71ac61e
13 changed files with 299 additions and 242 deletions
|
|
@ -184,6 +184,8 @@ func NewData(taoLogger *logger.TaoLogger) *Data {
|
|||
|
||||
func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
||||
|
||||
d.taoLogger.Log.Debug("invoke GetRecipe", zap.String("countryID", countryID), zap.String("filename", filename))
|
||||
|
||||
if countryID == "" {
|
||||
return d.currentRecipe["tha"]
|
||||
}
|
||||
|
|
@ -194,7 +196,7 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
|
||||
if recipe, ok := d.recipeMap[filename]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
return recipe.Recipe[countryID]
|
||||
}
|
||||
|
||||
|
|
@ -204,13 +206,13 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
// d.CurrentFile[countryID] = filename
|
||||
d.taoLogger.Log.Debug("GetRecipe", zap.String("filename", filename), zap.String("countryID", countryID))
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
d.taoLogger.Log.Error("GetRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
return d.currentRecipe[countryID]
|
||||
}
|
||||
|
||||
|
|
@ -248,21 +250,41 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
|
||||
func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string) (models.Recipe01, error) {
|
||||
|
||||
// try convert
|
||||
if len(countryID) != 3 {
|
||||
for k, v := range d.CurrentCountryID {
|
||||
fmt.Println("GetRecipe01ByProductCode.Iterate", k, v, v == countryID)
|
||||
if v == countryID {
|
||||
countryID = k
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println("GetRecipe01ByProductCode", filename, countryID, productCode)
|
||||
|
||||
if !strings.Contains(filename, "tmp") {
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadCurrent", filename, d.CurrentFile)
|
||||
// , d.CurrentFile, countryID, "result by country id", len(d.currentRecipe[countryID].Recipe01)
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::filename", filename)
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::countryID", countryID)
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::CurrentFile", d.CurrentFile)
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadCurrent::CurrentCountryID", d.CurrentCountryID)
|
||||
|
||||
for _, v := range d.currentRecipe[countryID].Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
fmt.Println("No result in current recipe", countryID)
|
||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile)
|
||||
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile, recipe.Recipe[countryID], "countryID=", countryID)
|
||||
for _, v := range recipe.Recipe[countryID].Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getSuccess", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
d.taoLogger.Log.Debug("GetRecipe01ByProductCode.getFail", zap.Any("fromFile", filename), zap.Any("whereSource", d.recipeMap))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -272,12 +294,12 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
|
||||
for _, v := range countries {
|
||||
if v.CountryName == countryID {
|
||||
d.CurrentCountryID[countryID] = v.CountryID
|
||||
// d.CurrentCountryID[countryID] = v.CountryID
|
||||
countryID = v.CountryID
|
||||
break
|
||||
}
|
||||
|
|
@ -286,7 +308,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
|||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
d.taoLogger.Log.Error("GetRecipe01ByProductCode: Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
for _, v := range d.currentRecipe[countryID].Recipe01 {
|
||||
if v.ProductCode == productCode {
|
||||
return v, nil
|
||||
|
|
@ -373,15 +395,15 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
|
||||
if !strings.Contains(filename, "tmp") {
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
copy(result, d.currentRecipe[countryID].MaterialSetting)
|
||||
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
|
||||
// copy(result, d.currentRecipe[countryID].MaterialSetting)
|
||||
// d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
|
||||
return d.currentRecipe[countryID].MaterialSetting
|
||||
}
|
||||
|
||||
if recipe, ok := d.recipeMap[filename]; ok {
|
||||
copy(result, recipe.Recipe[countryID].MaterialSetting)
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
return d.currentRecipe[countryID].MaterialSetting
|
||||
}
|
||||
}
|
||||
|
|
@ -390,19 +412,19 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("filename", filename), zap.Any("countryID", countryID))
|
||||
// d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("filename", filename), zap.Any("countryID", countryID))
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
d.taoLogger.Log.Error("GetMaterialSetting: Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
copy(result, d.currentRecipe[countryID].MaterialSetting)
|
||||
return d.currentRecipe[countryID].MaterialSetting
|
||||
}
|
||||
|
||||
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting))
|
||||
// d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting))
|
||||
|
||||
d.currentRecipe[countryID] = recipe
|
||||
|
||||
|
|
@ -443,12 +465,12 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
|
|||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
d.taoLogger.Log.Error("GetMaterialCode: Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
return d.currentRecipe[countryID].MaterialCode
|
||||
}
|
||||
|
||||
|
|
@ -510,12 +532,12 @@ func (d *Data) GetToppings(countryID, filename string) models.Topping {
|
|||
filename = d.CurrentFile[countryID]
|
||||
}
|
||||
|
||||
d.CurrentFile[countryID] = filename
|
||||
d.CurrentCountryID[countryID] = countryID
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
d.taoLogger.Log.Error("GetToppings: Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
return d.currentRecipe[countryID].Topping
|
||||
}
|
||||
|
||||
|
|
@ -533,7 +555,7 @@ func (d *Data) GetToppingsOfRecipe(countryID, filename string, productCode strin
|
|||
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
d.taoLogger.Log.Error("GetToppingOfRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
return []models.ToppingSet{}, err
|
||||
}
|
||||
|
||||
|
|
@ -549,7 +571,7 @@ func (d *Data) GetSubmenusOfRecipe(countryID, filename, productCode string) ([]m
|
|||
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
|
||||
|
||||
if err != nil {
|
||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
d.taoLogger.Log.Error("GetSubmenusOfRecipe: Error when read recipe file, Return default recipe", zap.Error(err))
|
||||
return []models.Recipe01{}, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
|
|||
countryID, err := mr.data.GetCountryIDByName(country)
|
||||
|
||||
if err != nil {
|
||||
mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
|
||||
// mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
|
||||
http.Error(w, "Country not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
|
|||
|
||||
matIDuint, err := strconv.ParseUint(matID, 10, 64)
|
||||
if err != nil {
|
||||
mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
|
||||
// mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
|
||||
http.Error(w, "Invalid material id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ func (mr *MaterialRouter) getMaterialSettingByMatID(w http.ResponseWriter, r *ht
|
|||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(matSetting); err != nil {
|
||||
mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
|
||||
// mr.taoLogger.Log.Error("MaterialRouter.GetMaterialSettingByMatID", zap.Error(err))
|
||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
|||
return contracts.RecipeDetailMatListResponse{}, fmt.Errorf("country name: %s not found", request.Country)
|
||||
}
|
||||
|
||||
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("request", request))
|
||||
rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("request", request))
|
||||
|
||||
recipe, err := rs.db.GetRecipe01ByProductCode(request.Filename, request.Country, request.ProductCode)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue