fix show toppingset unmatch index

This commit is contained in:
pakintada@gmail.com 2024-01-21 15:18:33 +07:00
parent d1330e4f84
commit ecd88b2e27
6 changed files with 218 additions and 76 deletions

View file

@ -61,6 +61,9 @@ func (rr *RecipeRouter) Route(r chi.Router) {
r.Get("/{country}/{filename}/{product_code}/submenus", rr.getSubmenusOfRecipe)
// fetch raw recipe json
r.Get("/{country}/{filename}/{product_code}/raw_full", rr.getRawRecipeOfProductCode)
r.Get("/{country}/{filename}/json", rr.getRecipeJson)
r.Post("/edit/{country}/{filename}", rr.updateRecipe)
@ -546,6 +549,31 @@ func (rr *RecipeRouter) getSubmenusOfRecipe(w http.ResponseWriter, r *http.Reque
json.NewEncoder(w).Encode(submenus)
}
// get raw recipe
func (rr *RecipeRouter) getRawRecipeOfProductCode(w http.ResponseWriter, r *http.Request) {
countryID := chi.URLParam(r, "country")
filename := chi.URLParam(r, "filename")
productCode := chi.URLParam(r, "product_code")
// debug
rr.taoLogger.Log.Debug("RecipeRouter.getRawRecipeOfProductCode", zap.Any("countryID", countryID), zap.Any("filename", filename), zap.Any("productCode", productCode))
w.Header().Add("Content-Type", "application/json")
recipe, err := rr.data.GetRecipe01ByProductCode(filename, countryID, productCode)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
// return recipe
rr.taoLogger.Log.Debug("RecipeRouter.getRawRecipeOfProductCode", zap.Any("recipe", recipe))
json.NewEncoder(w).Encode(recipe)
}
func (rr *RecipeRouter) doMergeJson(w http.ResponseWriter, r *http.Request) {
// TODO: v2, change to binary instead
if !APIhandler(w, r) {