adjust mat selection
This commit is contained in:
parent
17030c72ce
commit
bf693aab2a
15 changed files with 548 additions and 186 deletions
|
|
@ -2,14 +2,15 @@ package routers
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
"recipe-manager/data"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/services/logger"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MaterialRouter struct {
|
||||
|
|
@ -29,9 +30,72 @@ func (mr *MaterialRouter) Route(r chi.Router) {
|
|||
r.Get("/code", mr.getMaterialCode)
|
||||
|
||||
r.Get("/setting/{mat_id}", mr.getMaterialSettingByMatID)
|
||||
|
||||
r.Get("/full/{country}/{filename}", mr.GetFullMaterialDetail)
|
||||
})
|
||||
}
|
||||
|
||||
func (mr *MaterialRouter) GetFullMaterialDetail(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
country := chi.URLParam(r, "country")
|
||||
filename := chi.URLParam(r, "filename")
|
||||
|
||||
mr.taoLogger.Log.Debug("GetFullMaterialDetail", zap.Any("country", country), zap.Any("filename", filename))
|
||||
|
||||
// get material setting and code
|
||||
matSettings := mr.data.GetMaterialSetting(country, filename)
|
||||
matCodes := mr.data.GetRecipe(country, filename).MaterialCode
|
||||
|
||||
// combine
|
||||
materialDetails := []map[string]interface{}{}
|
||||
|
||||
for _, matSetting := range matSettings {
|
||||
|
||||
// if material name exist
|
||||
mat_name := ""
|
||||
if matSetting.MaterialName != "" {
|
||||
mat_name = matSetting.MaterialName
|
||||
// mr.taoLogger.Log.Debug("GetFullMaterialDetail", zap.Any("mat_name", mat_name))
|
||||
} else {
|
||||
|
||||
for _, matCode := range matCodes {
|
||||
if matCode.MaterialID == matSetting.ID {
|
||||
mat_name = matCode.PackageDescription
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
materialDetails = append(materialDetails, map[string]interface{}{
|
||||
"materialId": matSetting.ID,
|
||||
"name": mat_name,
|
||||
"type": "powder:" + strconv.FormatBool(matSetting.PowderChannel) + ",syrup:" + strconv.FormatBool(matSetting.SyrupChannel) + ",bean:" + strconv.FormatBool(matSetting.BeanChannel) + ",equipment:" + strconv.FormatBool(matSetting.IsEquipment),
|
||||
})
|
||||
}
|
||||
|
||||
// for _, matCode := range matCodes {
|
||||
// for index, matDetail := range materialDetails {
|
||||
// if matCode.MaterialID == matDetail["materialId"] {
|
||||
// materialDetails[index]["name"] = matCode.PackageDescription
|
||||
// } else if matDetail["materialId"].(uint64) > 8110 && matDetail["materialId"].(uint64) <= 8130 {
|
||||
// slotNum := matDetail["materialId"].(uint64) - 8110
|
||||
// // mr.taoLogger.Log.Debug("GetFullMaterialDetail", zap.Any("slotNum", matDetail["materialId"]), zap.Any("slotNum", slotNum))
|
||||
// materialDetails[index]["name"] = "Topping" + strconv.Itoa(int(slotNum))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// send result
|
||||
if err := json.NewEncoder(w).Encode(materialDetails); err != nil {
|
||||
mr.taoLogger.Log.Error("MaterialRouter.GetFullMaterialDetail", zap.Error(err))
|
||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (mr *MaterialRouter) getMaterialCode(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue