Cart fixes (backend), adjusted header, added footer, mobile formatting updates

This commit is contained in:
augmentedpotato
2026-04-14 05:24:40 -06:00
parent 8e205ebca2
commit 7bddd74a6e
13 changed files with 769 additions and 107 deletions

View File

@@ -91,4 +91,13 @@ public class CartController {
return ResponseEntity.noContent().build();
}
@PostMapping("/checkout/cancel")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Void> cancelCheckout(@RequestParam Long storeId) {
Long userId = AuthenticationHelper.getAuthenticatedUserId();
cartService.cancelCheckout(userId, storeId);
return ResponseEntity.noContent().build();
}
}

View File

@@ -16,6 +16,7 @@ public class CartResponse {
private String couponCode;
private Boolean pointsApplied;
private Integer availableLoyaltyPoints;
private Boolean checkoutPending;
public CartResponse() {
}
@@ -53,4 +54,7 @@ public class CartResponse {
public Integer getAvailableLoyaltyPoints() { return availableLoyaltyPoints; }
public void setAvailableLoyaltyPoints(Integer availableLoyaltyPoints) { this.availableLoyaltyPoints = availableLoyaltyPoints; }
public Boolean getCheckoutPending() { return checkoutPending; }
public void setCheckoutPending(Boolean checkoutPending) { this.checkoutPending = checkoutPending; }
}

View File

@@ -482,15 +482,21 @@ public class CartService {
List<CartItemResponse> itemResponses = cartItemRepository
.findByCartCartId(cart.getCartId())
.stream()
.map(item -> new CartItemResponse(
item.getCartItemId(),
item.getProduct().getProdId(),
item.getProduct().getProdName(),
item.getProduct().getImageUrl(),
item.getUnitPrice(),
item.getQuantity(),
item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()))
))
.map(item -> {
String rawImageUrl = item.getProduct().getImageUrl();
String imageUrl = (rawImageUrl != null && !rawImageUrl.isBlank())
? "/api/v1/products/" + item.getProduct().getProdId() + "/image"
: null;
return new CartItemResponse(
item.getCartItemId(),
item.getProduct().getProdId(),
item.getProduct().getProdName(),
imageUrl,
item.getUnitPrice(),
item.getQuantity(),
item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()))
);
})
.toList();
CartResponse response = new CartResponse();
@@ -505,7 +511,23 @@ public class CartService {
response.setCouponCode(cart.getCoupon() != null ? cart.getCoupon().getCouponCode() : null);
response.setPointsApplied(cart.getPointsApplied());
response.setAvailableLoyaltyPoints(cart.getUser() != null ? cart.getUser().getLoyaltyPoints() : null);
response.setCheckoutPending(cart.getCheckoutPending());
return response;
}
@Transactional
public void cancelCheckout(Long userId, Long storeId) {
cartRepository.findActiveCartByUserAndStore(userId, storeId, "ACTIVE")
.ifPresent(cart -> {
if (!Boolean.TRUE.equals(cart.getCheckoutPending())) {
return;
}
cart.setCheckoutPending(false);
cart.setCheckoutAmount(null);
cart.setCheckoutStartedAt(null);
cart.setCheckoutPaymentIntentId(null);
cartRepository.save(cart);
});
}
}