add carousel & test submenu

This commit is contained in:
pakintada@gmail.com 2024-01-15 11:48:25 +07:00
parent edcccaaab9
commit 7102f644d4
7 changed files with 242 additions and 314 deletions

View file

@ -426,6 +426,24 @@ func (d *Data) GetToppingsOfRecipe(countryID, filename string, productCode strin
return recipe.ToppingSet, nil
}
func (d *Data) GetSubmenusOfRecipe(countryID, filename, productCode string) ([]models.Recipe01, error) {
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))
return []models.Recipe01{}, err
}
submenu := recipe.SubMenu
if submenu == nil {
return []models.Recipe01{}, fmt.Errorf("no submenu")
}
return submenu, nil
}
func (d *Data) GetCountryNameByID(countryID string) (string, error) {
for _, country := range d.Countries {
if country.CountryID == countryID {

View file

@ -59,6 +59,8 @@ func (rr *RecipeRouter) Route(r chi.Router) {
r.Get("/{country}/{filename}/{product_code}/toppings", rr.getToppingsOfRecipe)
r.Get("/{country}/{filename}/{product_code}/submenus", rr.getSubmenusOfRecipe)
r.Get("/{country}/{filename}/json", rr.getRecipeJson)
r.Post("/edit/{country}/{filename}", rr.updateRecipe)
@ -520,6 +522,26 @@ func (rr *RecipeRouter) getToppingsOfRecipe(w http.ResponseWriter, r *http.Reque
json.NewEncoder(w).Encode(topps)
}
func (rr *RecipeRouter) getSubmenusOfRecipe(w http.ResponseWriter, r *http.Request) {
countryID := chi.URLParam(r, "country")
filename := chi.URLParam(r, "filename")
productCode := chi.URLParam(r, "product_code")
w.Header().Add("Content-Type", "application/json")
submenus, err := rr.data.GetSubmenusOfRecipe(countryID, filename, productCode)
rr.taoLogger.Log.Debug("RecipeRouter.getSubmenusOfRecipe", zap.Any("submenus", len(submenus)))
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
json.NewEncoder(w).Encode(submenus)
}
func (rr *RecipeRouter) doMergeJson(w http.ResponseWriter, r *http.Request) {
// TODO: v2, change to binary instead
if !APIhandler(w, r) {