Subversion Repositories SmartDukaan

Rev

Rev 36376 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36376 Rev 36479
Line 190... Line 190...
190
        }
190
        }
191
        return applyAndHydrate(ctx, desired);
191
        return applyAndHydrate(ctx, desired);
192
    }
192
    }
193
 
193
 
194
    /** Set a specific line's quantity. quantity=0 removes the line. */
194
    /** Set a specific line's quantity. quantity=0 removes the line. */
195
    @PatchMapping("/cart/items/{productId}")
195
    @PostMapping("/cart/items/{productId}")
196
    public ResponseEntity<?> updateQuantity(HttpServletRequest request,
196
    public ResponseEntity<?> updateQuantity(HttpServletRequest request,
197
                                            @PathVariable int productId,
197
                                            @PathVariable int productId,
198
                                            @RequestParam int quantity)
198
                                            @RequestParam int quantity)
199
            throws ProfitMandiBusinessException {
199
            throws ProfitMandiBusinessException {
200
        java.util.Optional<AuthCtx> auth = resolveAuth(request);
200
        java.util.Optional<AuthCtx> auth = resolveAuth(request);
Line 219... Line 219...
219
            }
219
            }
220
            if (!found) {
220
            if (!found) {
221
                desired.add(new CartItem(quantity, productId));
221
                desired.add(new CartItem(quantity, productId));
222
            }
222
            }
223
        }
223
        }
-
 
224
        // Skip carry bag rebalance if user explicitly changed carry bag qty
-
 
225
        if (productId == ProfitMandiConstants.ITEM_CARRY_BAG) {
-
 
226
            enrichPrices(ctx, desired);
-
 
227
            cartService.addItemsToCart(ctx.cartId, desired);
-
 
228
            return ResponseEntity.ok(ApiResponse.success(
-
 
229
                    cartValidationService.validateForOpen(ctx.cartId, ctx.storeId)));
-
 
230
        }
224
        return applyAndHydrate(ctx, desired);
231
        return applyAndHydrate(ctx, desired);
225
    }
232
    }
226
 
233
 
227
    /** Remove a single line by productId. */
234
    /** Remove a single line by productId. */
228
    @DeleteMapping("/cart/items/{productId}")
235
    @DeleteMapping("/cart/items/{productId}")
Line 233... Line 240...
233
        if (!auth.isPresent()) return unauthorized();
240
        if (!auth.isPresent()) return unauthorized();
234
        AuthCtx ctx = auth.get();
241
        AuthCtx ctx = auth.get();
235
        List<CartItem> desired = currentLinesAsItems(ctx.cartId).stream()
242
        List<CartItem> desired = currentLinesAsItems(ctx.cartId).stream()
236
                .filter(ci -> ci.getItemId() != productId)
243
                .filter(ci -> ci.getItemId() != productId)
237
                .collect(Collectors.toList());
244
                .collect(Collectors.toList());
-
 
245
        // Skip carry bag rebalance if user explicitly removed the carry bag
-
 
246
        if (productId == ProfitMandiConstants.ITEM_CARRY_BAG) {
-
 
247
            enrichPrices(ctx, desired);
-
 
248
            cartService.addItemsToCart(ctx.cartId, desired);
-
 
249
            return ResponseEntity.ok(ApiResponse.success(
-
 
250
                    cartValidationService.validateForOpen(ctx.cartId, ctx.storeId)));
-
 
251
        }
238
        return applyAndHydrate(ctx, desired);
252
        return applyAndHydrate(ctx, desired);
239
    }
253
    }
240
 
254
 
241
    /** Clear the entire cart. */
255
    /** Clear the entire cart. */
242
    @DeleteMapping("/cart")
256
    @DeleteMapping("/cart")