still have some bug about select file

This commit is contained in:
Kenta420 2023-10-20 17:51:07 +07:00
commit ad32fe38ea
11 changed files with 325 additions and 130 deletions

View file

@ -8,7 +8,14 @@ import (
"path/filepath"
"recipe-manager/helpers"
"recipe-manager/models"
"recipe-manager/services/logger"
"time"
"go.uber.org/zap"
)
var (
Log = logger.GetInstance()
)
func readFile(version string) *models.Recipe {
@ -123,6 +130,27 @@ func (d *Data) GetRecipe01() []models.Recipe01 {
return d.currentRecipe.Recipe01
}
func (d *Data) GetRecipe01ByProductCode(code string) models.Recipe01 {
result := make([]models.Recipe01, 0)
for _, v := range d.currentRecipe.Recipe01 {
if v.ProductCode == code {
result = append(result, v)
}
}
return result[0]
}
func (d *Data) SetValuesToRecipe(recipe models.Recipe01) {
for _, v := range d.currentRecipe.Recipe01 {
if v.ProductCode == recipe.ProductCode {
v = recipe
break
}
}
}
func (d *Data) GetMaterialSetting(version string) []models.MaterialSetting {
result := make([]models.MaterialSetting, 0)
@ -235,3 +263,13 @@ func (d *Data) GetCountryIDByName(countryName string) (string, error) {
}
return "", fmt.Errorf("country name: %s not found", countryName)
}
func (d *Data) ExportToJSON() []byte {
b_recipe, err := json.Marshal(d.currentRecipe)
if err != nil {
Log.Error("Error when marshal recipe", zap.Error(err))
return nil
}
return b_recipe
}