From 7db70f34d20fee422cc0e9ba3ba9600ca823b20a Mon Sep 17 00:00:00 2001 From: ankit-mogha Date: Thu, 7 Sep 2023 13:00:52 +0530 Subject: [PATCH] Done the enhancement in shipment service --- .../shipment/aggregate/ShipmentAggregate.java | 35 +------------------ .../handler/ShipmentEventHandler.java | 15 +------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/ShipmentService/src/main/java/com/nashtech/shipment/aggregate/ShipmentAggregate.java b/ShipmentService/src/main/java/com/nashtech/shipment/aggregate/ShipmentAggregate.java index 39ee46a5..4aa5fdc8 100644 --- a/ShipmentService/src/main/java/com/nashtech/shipment/aggregate/ShipmentAggregate.java +++ b/ShipmentService/src/main/java/com/nashtech/shipment/aggregate/ShipmentAggregate.java @@ -1,11 +1,8 @@ package com.nashtech.shipment.aggregate; -import com.nashtech.common.command.CancelShipmentCommand; import com.nashtech.common.command.CreatedShipmentCommand; -import com.nashtech.common.event.ShipmentCancelledEvent; import com.nashtech.common.event.ShipmentCreatedEvent; import com.nashtech.common.model.ShipmentStatus; -import com.nashtech.shipment.handler.ShipmentEventHandler; import org.axonframework.commandhandling.CommandHandler; import org.axonframework.eventsourcing.EventSourcingHandler; import org.axonframework.modelling.command.AggregateIdentifier; @@ -17,7 +14,7 @@ @Aggregate public class ShipmentAggregate { - private final Logger LOGGER = LoggerFactory.getLogger(ShipmentEventHandler.class); + private final Logger LOGGER = LoggerFactory.getLogger(ShipmentAggregate.class); @AggregateIdentifier private String shipmentId; @@ -26,7 +23,6 @@ public class ShipmentAggregate { private Integer quantity; private Double price; private String userId; - private String reasonToFailed; private String paymentId; private ShipmentStatus shipmentStatus; @@ -48,22 +44,6 @@ public ShipmentAggregate(CreatedShipmentCommand createdShipmentCommand) { AggregateLifecycle.apply(shipmentCreatedEvent); } - @CommandHandler - public void handle(CancelShipmentCommand cancelShipmentCommand) { - LOGGER.info("CancelShipmentCommand is called for shipmentId: {}", cancelShipmentCommand.getShipmentId()); - ShipmentCancelledEvent shipmentCancelledEvent = ShipmentCancelledEvent.builder() - .shipmentId(cancelShipmentCommand.getShipmentId()) - .orderId(cancelShipmentCommand.getOrderId()) - .productId(cancelShipmentCommand.getProductId()) - .quantity(cancelShipmentCommand.getQuantity()) - .price(cancelShipmentCommand.getPrice()) - .userId(cancelShipmentCommand.getUserId()) - .reasonToFailed(cancelShipmentCommand.getReasonToFailed()) - .paymentId(cancelShipmentCommand.getPaymentId()) - .shipmentStatus(cancelShipmentCommand.getShipmentStatus()).build(); - AggregateLifecycle.apply(shipmentCancelledEvent); - } - @EventSourcingHandler public void on(ShipmentCreatedEvent shipmentCreatedEvent) { this.shipmentId = shipmentCreatedEvent.getShipmentId(); @@ -75,17 +55,4 @@ public void on(ShipmentCreatedEvent shipmentCreatedEvent) { this.paymentId = shipmentCreatedEvent.getPaymentId(); this.shipmentStatus = shipmentCreatedEvent.getShipmentStatus(); } - - @EventSourcingHandler - public void on(ShipmentCancelledEvent shipmentCancelledEvent) { - this.shipmentId = shipmentCancelledEvent.getShipmentId(); - this.orderId = shipmentCancelledEvent.getOrderId(); - this.productId = shipmentCancelledEvent.getProductId(); - this.quantity = shipmentCancelledEvent.getQuantity(); - this.price = shipmentCancelledEvent.getPrice(); - this.userId = shipmentCancelledEvent.getUserId(); - this.reasonToFailed = shipmentCancelledEvent.getReasonToFailed(); - this.paymentId = shipmentCancelledEvent.getPaymentId(); - this.shipmentStatus = shipmentCancelledEvent.getShipmentStatus(); - } } diff --git a/ShipmentService/src/main/java/com/nashtech/shipment/handler/ShipmentEventHandler.java b/ShipmentService/src/main/java/com/nashtech/shipment/handler/ShipmentEventHandler.java index e932c347..ffddf114 100644 --- a/ShipmentService/src/main/java/com/nashtech/shipment/handler/ShipmentEventHandler.java +++ b/ShipmentService/src/main/java/com/nashtech/shipment/handler/ShipmentEventHandler.java @@ -1,6 +1,5 @@ package com.nashtech.shipment.handler; -import com.nashtech.common.event.ShipmentCancelledEvent; import com.nashtech.common.event.ShipmentCreatedEvent; import com.nashtech.shipment.entity.ShipmentEntity; import com.nashtech.shipment.repository.ShipmentRepository; @@ -21,7 +20,7 @@ public ShipmentEventHandler(ShipmentRepository shipmentRepository) { @EventHandler public void on(ShipmentCreatedEvent shipmentCreatedEvent) { - LOGGER.info("ShipmentCreatedEvent is called for shipmentId: " + shipmentCreatedEvent.getShipmentId()); + LOGGER.info("ShipmentCreatedEvent is called for shipmentId: {}", shipmentCreatedEvent.getShipmentId()); ShipmentEntity shipmentEntity = new ShipmentEntity( shipmentCreatedEvent.getShipmentId(), shipmentCreatedEvent.getOrderId(), @@ -34,16 +33,4 @@ public void on(ShipmentCreatedEvent shipmentCreatedEvent) { ); shipmentRepository.save(shipmentEntity); } - - @EventHandler - public void on(ShipmentCancelledEvent shipmentCancelledEvent) { - ShipmentEntity shipmentEntity = shipmentRepository.findByOrderId(shipmentCancelledEvent.getOrderId()); - if (shipmentEntity == null) { - LOGGER.info("No record found for orderId: {}", shipmentCancelledEvent.getOrderId()); - } else { - LOGGER.info("ShipmentCancelEvent is called for shipmentId: {}", shipmentCancelledEvent.getShipmentId()); - shipmentEntity.setShipmentStatus(shipmentCancelledEvent.getShipmentStatus()); - shipmentRepository.save(shipmentEntity); - } - } }