Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/cart/controller/CartController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cart.model.Cart;
import cart.service.CartService;
import com.podzilla.mq.events.ConfirmationType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -48,8 +49,7 @@ public class CartController {
description = "Internal server error",
content = @Content)
})



@PostMapping("/create")
public ResponseEntity<Cart> createCart(
@RequestHeader("X-User-Id") final String customerId) {
Expand Down Expand Up @@ -235,14 +235,14 @@ public ResponseEntity<Cart> unarchiveCart(
@PostMapping("/checkout")
public ResponseEntity<Cart> checkoutCart(
@RequestHeader("X-User-Id") final String customerId,
@RequestParam(required = true) final com.podzilla.mq.events.ConfirmationType confirmationType,
@RequestParam(required = true) final ConfirmationType confirmationType,
@RequestParam(required = false) final String signature,
@RequestParam(required = true) final Double longitude,
@RequestParam(required = true) final Double latitude,
@RequestParam(required = true) final DeliveryAddress address
) {
log.debug("Entering checkoutCart endpoint with customerId: {}," +
" confirmationType: {}, signature: {}",
log.debug("Entering checkoutCart endpoint with customerId: {},"
+ " confirmationType: {}, signature: {}",
customerId, confirmationType, signature);
try {
Cart updatedCart = cartService.checkoutCart(customerId, confirmationType,
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/cart/service/CartService.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ private BigDecimal calculateSubTotal(final Cart cart) {
}

public Cart checkoutCart(final String customerId, final ConfirmationType confirmationType,
final String signature, final Double longitude, final Double latitude, DeliveryAddress address) {
log.debug("Entering checkoutCart for customerId: {} with confirmationType: {}",
final String signature, final Double longitude, final Double latitude, final DeliveryAddress address) {
log.debug("Entering checkoutCart for customerId: {} with confirmationType: {}",
customerId, confirmationType);
Cart cart = getActiveCart(customerId);

Expand All @@ -265,7 +265,8 @@ public Cart checkoutCart(final String customerId, final ConfirmationType confirm
}

if (confirmationType == ConfirmationType.SIGNATURE && (signature == null || signature.trim().isEmpty())) {
throw new GlobalHandlerException(HttpStatus.BAD_REQUEST, "Signature is required for SIGNATURE confirmation type");
throw new GlobalHandlerException(HttpStatus.BAD_REQUEST,
"Signature is required for SIGNATURE confirmation type");
}

List<OrderItem> orderItems = cart.getItems().stream()
Expand All @@ -279,7 +280,7 @@ public Cart checkoutCart(final String customerId, final ConfirmationType confirm
CartCheckedoutEvent checkoutEvent = CartCheckedoutEvent.builder()
.cartId(cart.getId())
.customerId(customerId)
.items(orderItems)
.items(orderItems)
.totalAmount(cart.getTotalPrice())
.deliveryAddress(address)
.orderLatitude(latitude != null ? latitude : 0.0)
Expand All @@ -289,8 +290,10 @@ public Cart checkoutCart(final String customerId, final ConfirmationType confirm
.build();

try {
log.debug("Publishing checkout event for cartId: {} with totals: Sub={}, Discount={}, Total={}, ConfirmationType={}",
cart.getId(), cart.getSubTotal(), cart.getDiscountAmount(), cart.getTotalPrice(), confirmationType);
log.debug("Publishing checkout event for cartId: {} with totals: Sub={},"
+ " Discount={}, Total={}, ConfirmationType={}",
cart.getId(), cart.getSubTotal(), cart.getDiscountAmount(),
cart.getTotalPrice(), confirmationType);
eventPublisher.publishEvent(EventsConstants.ORDER_PLACED, checkoutEvent);

log.info("Checkout event published successfully for cartId: {}. Clearing cart.", cart.getId());
Expand Down