Skip to content

Commit

Permalink
Merge pull request #9 from NashTech-Labs/feature/Enhancement-shipment…
Browse files Browse the repository at this point in the history
…-service

Done the enhancement in shipment service
  • Loading branch information
ankit-mogha authored Sep 7, 2023
2 parents c7a2575 + 7db70f3 commit aea32ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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();
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(),
Expand All @@ -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);
}
}
}

0 comments on commit aea32ae

Please sign in to comment.