update
This commit is contained in:
@@ -106,8 +106,8 @@ func main() {
|
||||
mux.HandleFunc("GET /carts", fs.CartsHandler)
|
||||
mux.HandleFunc("GET /cart/{id}", fs.CartHandler)
|
||||
mux.HandleFunc("PUT /inventory/{locationId}/{sku}", func(w http.ResponseWriter, r *http.Request) {
|
||||
inventoryLocationId := r.PathValue("locationId")
|
||||
inventorySku := r.PathValue("sku")
|
||||
inventoryLocationId := inventory.LocationID(r.PathValue("locationId"))
|
||||
inventorySku := inventory.SKU(r.PathValue("sku"))
|
||||
pipe := rdb.Pipeline()
|
||||
var payload struct {
|
||||
Quantity int64 `json:"quantity"`
|
||||
@@ -117,12 +117,18 @@ func main() {
|
||||
http.Error(w, "invalid payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
inventoryService.UpdateInventory(r.Context(), pipe, inventory.SKU(inventorySku), inventory.LocationID(inventoryLocationId), payload.Quantity)
|
||||
inventoryService.UpdateInventory(r.Context(), pipe, inventorySku, inventoryLocationId, payload.Quantity)
|
||||
|
||||
_, err = pipe.Exec(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "failed to update inventory", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err := inventoryService.SendInventoryChanged(r.Context(), inventorySku, inventoryLocationId)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
mux.HandleFunc("/promotions", fs.PromotionsHandler)
|
||||
|
||||
Reference in New Issue
Block a user