From 46dd82ebbdac86701aedccc7712ef396da459507 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 16 Mar 2016 01:03:37 +0100 Subject: fix creation of carts for shows diff --git a/rhimport/importer.go b/rhimport/importer.go index 4473ee4..73d446e 100644 --- a/rhimport/importer.go +++ b/rhimport/importer.go @@ -393,20 +393,29 @@ func clearShowCarts(ctx *Context, res *Result, carts []uint) (err error) { } func addShowCartCut(ctx *Context, res *Result, carts []uint) (err error) { - if err = addCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { - return + if ctx.Cart != 0 { + return addCartCut(ctx, res) } + for _, cart := range carts { - if cart == ctx.Cart { - if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { - return removeCart(ctx, &Result{ResponseCode: http.StatusOK}) + ctx.Cart = cart + if err = addCart(ctx, res); err != nil { + return + } + switch res.ResponseCode { + case http.StatusOK: + { + if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK { + return removeCart(ctx, &Result{ResponseCode: http.StatusOK}) + } + return } + case http.StatusForbidden: // Cart already exists + continue + default: return } } - if err = removeCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK { - return - } res.ResponseCode = http.StatusForbidden res.ErrorString = fmt.Sprintf("Show %d has no free carts left", ctx.ShowId) return -- cgit v0.10.2