From 5e40b1569b2ff1dfdd92b8296b0d24c5da0c810e Mon Sep 17 00:00:00 2001 From: deepak1067 Date: Thu, 7 Sep 2023 16:41:04 +0530 Subject: [PATCH] Structure fixed --- .../common/command/CancelPaymentCommand.java | 2 ++ .../common/command/ProcessPaymentCommand.java | 3 ++ .../common/event/PaymentApprovedEvent.java | 3 ++ .../common/event/PaymentCancelledEvent.java | 3 ++ .../nashtech/common/model/PaymentStatus.java | 0 .../java/com/nashtech/common/model/User.java | 1 - .../common/commands/CancelPaymentCommand.java | 21 ------------ .../commands/ProcessPaymentCommand.java | 25 -------------- .../common/events/PaymentCancelledEvent.java | 18 ---------- .../common/events/PaymentProcessedEvent.java | 18 ---------- .../nashtech/common/model/PaymentDetails.java | 14 -------- .../java/com/nashtech/common/model/User.java | 13 -------- PaymentService/pom.xml | 4 +-- .../{ => aggregate}/PaymentAggregate.java | 33 +++++++++---------- .../{ => handler}/PaymentsEventHandler.java | 23 +++++++------ 15 files changed, 40 insertions(+), 141 deletions(-) rename {CommonService => Common}/src/main/java/com/nashtech/common/model/PaymentStatus.java (100%) delete mode 100644 CommonService/src/main/java/com/nashtech/common/commands/CancelPaymentCommand.java delete mode 100644 CommonService/src/main/java/com/nashtech/common/commands/ProcessPaymentCommand.java delete mode 100644 CommonService/src/main/java/com/nashtech/common/events/PaymentCancelledEvent.java delete mode 100644 CommonService/src/main/java/com/nashtech/common/events/PaymentProcessedEvent.java delete mode 100644 CommonService/src/main/java/com/nashtech/common/model/PaymentDetails.java delete mode 100644 CommonService/src/main/java/com/nashtech/common/model/User.java rename PaymentService/src/main/java/com/nashtech/payment/command/{ => aggregate}/PaymentAggregate.java (65%) rename PaymentService/src/main/java/com/nashtech/payment/events/{ => handler}/PaymentsEventHandler.java (52%) diff --git a/Common/src/main/java/com/nashtech/common/command/CancelPaymentCommand.java b/Common/src/main/java/com/nashtech/common/command/CancelPaymentCommand.java index 000af054..b41285cd 100644 --- a/Common/src/main/java/com/nashtech/common/command/CancelPaymentCommand.java +++ b/Common/src/main/java/com/nashtech/common/command/CancelPaymentCommand.java @@ -1,5 +1,6 @@ package com.nashtech.common.command; +import com.nashtech.common.model.PaymentStatus; import lombok.Builder; import lombok.Value; import org.axonframework.modelling.command.TargetAggregateIdentifier; @@ -15,5 +16,6 @@ public class CancelPaymentCommand { String reasonToFailed; String productId; Double price; + PaymentStatus paymentStatus = PaymentStatus.PAYMENT_CANCELED; } diff --git a/Common/src/main/java/com/nashtech/common/command/ProcessPaymentCommand.java b/Common/src/main/java/com/nashtech/common/command/ProcessPaymentCommand.java index dcf2fd72..32e08c7e 100644 --- a/Common/src/main/java/com/nashtech/common/command/ProcessPaymentCommand.java +++ b/Common/src/main/java/com/nashtech/common/command/ProcessPaymentCommand.java @@ -1,6 +1,7 @@ package com.nashtech.common.command; import com.nashtech.common.model.PaymentDetails; +import com.nashtech.common.model.PaymentStatus; import com.nashtech.common.model.User; import lombok.Builder; import lombok.Value; @@ -17,5 +18,7 @@ public class ProcessPaymentCommand { String productId; User userDetails; PaymentDetails paymentDetails; + PaymentStatus paymentStatus = PaymentStatus.PAYMENT_APPROVED; + } \ No newline at end of file diff --git a/Common/src/main/java/com/nashtech/common/event/PaymentApprovedEvent.java b/Common/src/main/java/com/nashtech/common/event/PaymentApprovedEvent.java index 102cf1d5..5122d3f7 100644 --- a/Common/src/main/java/com/nashtech/common/event/PaymentApprovedEvent.java +++ b/Common/src/main/java/com/nashtech/common/event/PaymentApprovedEvent.java @@ -1,5 +1,6 @@ package com.nashtech.common.event; +import com.nashtech.common.model.PaymentStatus; import lombok.Builder; import lombok.Value; @@ -12,5 +13,7 @@ public class PaymentApprovedEvent { String userId; Integer quantity; String productId; + PaymentStatus paymentStatus; + } \ No newline at end of file diff --git a/Common/src/main/java/com/nashtech/common/event/PaymentCancelledEvent.java b/Common/src/main/java/com/nashtech/common/event/PaymentCancelledEvent.java index b9b399b1..fef33e6e 100644 --- a/Common/src/main/java/com/nashtech/common/event/PaymentCancelledEvent.java +++ b/Common/src/main/java/com/nashtech/common/event/PaymentCancelledEvent.java @@ -1,15 +1,18 @@ package com.nashtech.common.event; +import com.nashtech.common.model.PaymentStatus; import lombok.Builder; import lombok.Value; @Value @Builder public class PaymentCancelledEvent { + String paymentId; String orderId; Integer quantity; String userId; String reason; String productId; + PaymentStatus paymentStatus; } diff --git a/CommonService/src/main/java/com/nashtech/common/model/PaymentStatus.java b/Common/src/main/java/com/nashtech/common/model/PaymentStatus.java similarity index 100% rename from CommonService/src/main/java/com/nashtech/common/model/PaymentStatus.java rename to Common/src/main/java/com/nashtech/common/model/PaymentStatus.java diff --git a/Common/src/main/java/com/nashtech/common/model/User.java b/Common/src/main/java/com/nashtech/common/model/User.java index 71d29a72..4c365d73 100644 --- a/Common/src/main/java/com/nashtech/common/model/User.java +++ b/Common/src/main/java/com/nashtech/common/model/User.java @@ -10,6 +10,5 @@ public class User { String lastName; String userId; String address; - PaymentDetails paymentDetails; } \ No newline at end of file diff --git a/CommonService/src/main/java/com/nashtech/common/commands/CancelPaymentCommand.java b/CommonService/src/main/java/com/nashtech/common/commands/CancelPaymentCommand.java deleted file mode 100644 index 8aaf7174..00000000 --- a/CommonService/src/main/java/com/nashtech/common/commands/CancelPaymentCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.nashtech.common.commands; - -import com.nashtech.common.model.PaymentStatus; -import lombok.Builder; -import lombok.Value; -import org.axonframework.modelling.command.TargetAggregateIdentifier; - -@Value -@Builder -public class CancelPaymentCommand { - - @TargetAggregateIdentifier - String paymentId; - String orderId; - Double price; - Integer quantity; - String userId; - String reasonToFailed; - String productId; - PaymentStatus paymentStatus = PaymentStatus.PAYMENT_CANCELED; -} diff --git a/CommonService/src/main/java/com/nashtech/common/commands/ProcessPaymentCommand.java b/CommonService/src/main/java/com/nashtech/common/commands/ProcessPaymentCommand.java deleted file mode 100644 index 57f1ec00..00000000 --- a/CommonService/src/main/java/com/nashtech/common/commands/ProcessPaymentCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nashtech.common.commands; - -import com.nashtech.common.model.PaymentDetails; -import com.nashtech.common.model.PaymentStatus; -import com.nashtech.common.model.User; -import lombok.Builder; -import lombok.Value; -import org.axonframework.modelling.command.TargetAggregateIdentifier; - -@Value -@Builder -public class ProcessPaymentCommand { - - @TargetAggregateIdentifier - String paymentId; - String orderId; - Double price; - Integer quantity; - String productId; - User userDetails; - PaymentDetails paymentDetails; - PaymentStatus paymentStatus = PaymentStatus.PAYMENT_APPROVED; - - -} diff --git a/CommonService/src/main/java/com/nashtech/common/events/PaymentCancelledEvent.java b/CommonService/src/main/java/com/nashtech/common/events/PaymentCancelledEvent.java deleted file mode 100644 index 3802646e..00000000 --- a/CommonService/src/main/java/com/nashtech/common/events/PaymentCancelledEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.nashtech.common.events; - -import com.nashtech.common.model.PaymentStatus; -import lombok.Builder; -import lombok.Value; - -@Value -@Builder -public class PaymentCancelledEvent { - String paymentId; - String orderId; - Integer quantity; - String userId; - String reason; - String productId; - PaymentStatus paymentStatus; - -} diff --git a/CommonService/src/main/java/com/nashtech/common/events/PaymentProcessedEvent.java b/CommonService/src/main/java/com/nashtech/common/events/PaymentProcessedEvent.java deleted file mode 100644 index a4aa81d1..00000000 --- a/CommonService/src/main/java/com/nashtech/common/events/PaymentProcessedEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.nashtech.common.events; - -import com.nashtech.common.model.PaymentStatus; -import lombok.Builder; - -import lombok.Value; - -@Value -@Builder -public class PaymentProcessedEvent { - String paymentId; - String orderId; - Double price; - String userId; - Integer quantity; - String productId; - PaymentStatus paymentStatus; -} \ No newline at end of file diff --git a/CommonService/src/main/java/com/nashtech/common/model/PaymentDetails.java b/CommonService/src/main/java/com/nashtech/common/model/PaymentDetails.java deleted file mode 100644 index 559e7277..00000000 --- a/CommonService/src/main/java/com/nashtech/common/model/PaymentDetails.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.nashtech.common.model; - -import lombok.Builder; -import lombok.Value; - -@Value -@Builder -public class PaymentDetails { - private String name; - private String cardNumber; - private Integer validUntilMonth; - private Integer validUntilYear; - private Integer cvv; -} diff --git a/CommonService/src/main/java/com/nashtech/common/model/User.java b/CommonService/src/main/java/com/nashtech/common/model/User.java deleted file mode 100644 index 2224a31f..00000000 --- a/CommonService/src/main/java/com/nashtech/common/model/User.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.nashtech.common.model; - -import lombok.Builder; -import lombok.Value; - -@Value -@Builder -public class User { - String firstName; - String lastName; - String userId; - String address; -} diff --git a/PaymentService/pom.xml b/PaymentService/pom.xml index 6fec5e54..770640e6 100644 --- a/PaymentService/pom.xml +++ b/PaymentService/pom.xml @@ -17,7 +17,7 @@ 19 8.0.33 4.8.1 - 0.0.1-SNAPSHOT + 1.0 @@ -49,7 +49,7 @@ com.nashtech.common - CommonService + Common ${common.version} diff --git a/PaymentService/src/main/java/com/nashtech/payment/command/PaymentAggregate.java b/PaymentService/src/main/java/com/nashtech/payment/command/aggregate/PaymentAggregate.java similarity index 65% rename from PaymentService/src/main/java/com/nashtech/payment/command/PaymentAggregate.java rename to PaymentService/src/main/java/com/nashtech/payment/command/aggregate/PaymentAggregate.java index c335aa50..e6b29972 100644 --- a/PaymentService/src/main/java/com/nashtech/payment/command/PaymentAggregate.java +++ b/PaymentService/src/main/java/com/nashtech/payment/command/aggregate/PaymentAggregate.java @@ -1,10 +1,9 @@ -package com.nashtech.payment.command; +package com.nashtech.payment.command.aggregate; -import com.nashtech.common.commands.CancelPaymentCommand; -import com.nashtech.common.commands.ProcessPaymentCommand; -import com.nashtech.common.events.PaymentCancelledEvent; -import com.nashtech.common.events.PaymentProcessedEvent; -import com.nashtech.common.model.PaymentStatus; +import com.nashtech.common.command.ProcessPaymentCommand; + +import com.nashtech.common.event.PaymentApprovedEvent; +import com.nashtech.common.event.PaymentCancelledEvent; import lombok.extern.slf4j.Slf4j; import org.axonframework.commandhandling.CommandHandler; import org.axonframework.eventsourcing.EventSourcingHandler; @@ -45,8 +44,8 @@ public PaymentAggregate(ProcessPaymentCommand processPaymentCommand) { return; } - PaymentProcessedEvent paymentProcessedEvent = - PaymentProcessedEvent.builder() + PaymentApprovedEvent paymentApprovedEvent = + PaymentApprovedEvent.builder() .orderId(processPaymentCommand.getOrderId()) .paymentId(processPaymentCommand.getPaymentId()) .productId(processPaymentCommand.getProductId()) @@ -55,18 +54,18 @@ public PaymentAggregate(ProcessPaymentCommand processPaymentCommand) { .paymentStatus(processPaymentCommand.getPaymentStatus()) .build(); - AggregateLifecycle.apply(paymentProcessedEvent); + AggregateLifecycle.apply(paymentApprovedEvent); } @EventSourcingHandler - public void on(PaymentProcessedEvent paymentProcessedEvent){ - this.paymentId = paymentProcessedEvent.getPaymentId(); - this.orderId = paymentProcessedEvent.getOrderId(); - this.productId = paymentProcessedEvent.getProductId(); - this.quantity = paymentProcessedEvent.getQuantity(); - this.price = paymentProcessedEvent.getPrice(); - this.userId = paymentProcessedEvent.getUserId(); - this.paymentStatus = String.valueOf(paymentProcessedEvent.getPaymentStatus()); + public void on(PaymentApprovedEvent paymentApprovedEvent){ + this.paymentId = paymentApprovedEvent.getPaymentId(); + this.orderId = paymentApprovedEvent.getOrderId(); + this.productId = paymentApprovedEvent.getProductId(); + this.quantity = paymentApprovedEvent.getQuantity(); + this.price = paymentApprovedEvent.getPrice(); + this.userId = paymentApprovedEvent.getUserId(); + this.paymentStatus = String.valueOf(paymentApprovedEvent.getPaymentStatus()); } } diff --git a/PaymentService/src/main/java/com/nashtech/payment/events/PaymentsEventHandler.java b/PaymentService/src/main/java/com/nashtech/payment/events/handler/PaymentsEventHandler.java similarity index 52% rename from PaymentService/src/main/java/com/nashtech/payment/events/PaymentsEventHandler.java rename to PaymentService/src/main/java/com/nashtech/payment/events/handler/PaymentsEventHandler.java index 8c129d1f..6deaf1a4 100644 --- a/PaymentService/src/main/java/com/nashtech/payment/events/PaymentsEventHandler.java +++ b/PaymentService/src/main/java/com/nashtech/payment/events/handler/PaymentsEventHandler.java @@ -1,7 +1,6 @@ -package com.nashtech.payment.events; +package com.nashtech.payment.events.handler; -import com.nashtech.common.events.PaymentCancelledEvent; -import com.nashtech.common.events.PaymentProcessedEvent; +import com.nashtech.common.event.PaymentApprovedEvent; import com.nashtech.payment.data.Payment; import com.nashtech.payment.data.PaymentsRepository; import org.axonframework.eventhandling.EventHandler; @@ -20,17 +19,17 @@ public PaymentsEventHandler(PaymentsRepository paymentsRepository) { } @EventHandler - public void on(PaymentProcessedEvent paymentProcessedEvent){ + public void on(PaymentApprovedEvent paymentApprovedEvent){ - LOGGER.info("PaymentProcessedEvent is called for orderId:{} ", paymentProcessedEvent.getOrderId()); + LOGGER.info("PaymentProcessedEvent is called for orderId:{} ", paymentApprovedEvent.getOrderId()); Payment payment = Payment.builder() - .paymentId(paymentProcessedEvent.getPaymentId()) - .orderId(paymentProcessedEvent.getOrderId()) - .productId(paymentProcessedEvent.getProductId()) - .quantity(String.valueOf(paymentProcessedEvent.getQuantity())) - .price(paymentProcessedEvent.getPrice()) - .userId(paymentProcessedEvent.getUserId()) - .paymentStatus(paymentProcessedEvent.getPaymentStatus()) + .paymentId(paymentApprovedEvent.getPaymentId()) + .orderId(paymentApprovedEvent.getOrderId()) + .productId(paymentApprovedEvent.getProductId()) + .quantity(String.valueOf(paymentApprovedEvent.getQuantity())) + .price(paymentApprovedEvent.getPrice()) + .userId(paymentApprovedEvent.getUserId()) + .paymentStatus(paymentApprovedEvent.getPaymentStatus()) .build(); paymentsRepository.save(payment);