add edit json v1 WIP, testing

This commit is contained in:
pakintada@gmail.com 2023-10-20 14:32:16 +07:00
parent e5eee656d5
commit ea92145350
11 changed files with 216 additions and 67 deletions

View file

@ -6,8 +6,15 @@ import (
"os"
"path/filepath"
"recipe-manager/models"
"recipe-manager/services/logger"
"sort"
"time"
"go.uber.org/zap"
)
var (
Log = logger.GetInstance()
)
func readFile(version string) *models.Recipe {
@ -131,6 +138,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)
@ -225,3 +253,13 @@ func (d *Data) GetMaterialCode(ids []uint64, version string) []models.MaterialCo
return resultFilter
}
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
}