add topping selection, defaultID WIP
This commit is contained in:
parent
2d753502f6
commit
3b4dec5e61
10 changed files with 331 additions and 56 deletions
|
|
@ -33,6 +33,7 @@ type RecipeRouter struct {
|
|||
|
||||
var (
|
||||
binaryApiLock sync.Mutex
|
||||
updateMutex = sync.Mutex{}
|
||||
)
|
||||
|
||||
func NewRecipeRouter(data *data.Data, recipeService recipe.RecipeService, sheetService sheet.SheetService, taoLogger *logger.TaoLogger) *RecipeRouter {
|
||||
|
|
@ -56,6 +57,8 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
|||
|
||||
r.Get("/{country}/{filename}/toppings", rr.getToppings)
|
||||
|
||||
r.Get("/{country}/{filename}/{product_code}/toppings", rr.getToppingsOfRecipe)
|
||||
|
||||
r.Get("/{country}/{filename}/json", rr.getRecipeJson)
|
||||
|
||||
r.Post("/edit/{country}/{filename}", rr.updateRecipe)
|
||||
|
|
@ -347,6 +350,9 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Lock
|
||||
updateMutex.Lock()
|
||||
defer updateMutex.Unlock()
|
||||
targetRecipe := rr.data.GetRecipe(countryID, filename)
|
||||
|
||||
rr.taoLogger.Log.Debug("Target => ", zap.Any("target", targetRecipe.MachineSetting.ConfigNumber))
|
||||
|
|
@ -495,39 +501,28 @@ func (rr *RecipeRouter) getToppings(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func (rr *RecipeRouter) getToppingsOfRecipe(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// countryID := chi.URLParam(r, "country")
|
||||
// filename := chi.URLParam(r, "filename")
|
||||
// productCode := chi.URLParam(r, "product_code")
|
||||
countryID := chi.URLParam(r, "country")
|
||||
filename := chi.URLParam(r, "filename")
|
||||
productCode := chi.URLParam(r, "product_code")
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
// all toppings
|
||||
// allToppings := rr.data.GetToppings(countryID, filename)
|
||||
|
||||
// topps, err := rr.data.GetToppingsOfRecipe(countryID, filename, productCode)
|
||||
topps, err := rr.data.GetToppingsOfRecipe(countryID, filename, productCode)
|
||||
|
||||
// expandedToppings := map[string]interface{}{}
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// for _, v := range allToppings.ToppingGroup {
|
||||
// for _, t := range topps {
|
||||
// if v.GroupID == t.ListGroupID[0] {
|
||||
// expandedToppings[v.GroupID] = v
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusNotFound)
|
||||
// return
|
||||
// }
|
||||
|
||||
// json.NewEncoder(w).Encode()
|
||||
json.NewEncoder(w).Encode(topps)
|
||||
}
|
||||
|
||||
func (rr *RecipeRouter) doMergeJson(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: v2, change to binary instead
|
||||
if !binaryAPIhandler(w, r) {
|
||||
if !APIhandler(w, r) {
|
||||
rr.taoLogger.Log.Warn("RecipeRouter.doMergeJson", zap.Error(errors.New("API is busy")))
|
||||
return
|
||||
} else {
|
||||
|
|
@ -537,7 +532,7 @@ func (rr *RecipeRouter) doMergeJson(w http.ResponseWriter, r *http.Request) {
|
|||
// TODO: add binary command here
|
||||
}
|
||||
|
||||
func binaryAPIhandler(w http.ResponseWriter, r *http.Request) bool {
|
||||
func APIhandler(w http.ResponseWriter, r *http.Request) bool {
|
||||
timeout := 10 * time.Second
|
||||
|
||||
if !lockThenTimeout(&binaryApiLock, timeout) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue