Skip to content

Commit

Permalink
Merge pull request #11 from NashTech-Labs/feature/fix-structure
Browse files Browse the repository at this point in the history
Structure fixed
  • Loading branch information
deepak1067 authored Sep 7, 2023
2 parents 0ba469c + 5e40b15 commit b7d55e8
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,5 +16,6 @@ public class CancelPaymentCommand {
String reasonToFailed;
String productId;
Double price;
PaymentStatus paymentStatus = PaymentStatus.PAYMENT_CANCELED;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,5 +18,7 @@ public class ProcessPaymentCommand {
String productId;
User userDetails;
PaymentDetails paymentDetails;
PaymentStatus paymentStatus = PaymentStatus.PAYMENT_APPROVED;


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nashtech.common.event;

import com.nashtech.common.model.PaymentStatus;
import lombok.Builder;
import lombok.Value;

Expand All @@ -12,5 +13,7 @@ public class PaymentApprovedEvent {
String userId;
Integer quantity;
String productId;
PaymentStatus paymentStatus;


}
Original file line number Diff line number Diff line change
@@ -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;

}
1 change: 0 additions & 1 deletion Common/src/main/java/com/nashtech/common/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ public class User {
String lastName;
String userId;
String address;
PaymentDetails paymentDetails;

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions CommonService/src/main/java/com/nashtech/common/model/User.java

This file was deleted.

4 changes: 2 additions & 2 deletions PaymentService/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<java.version>19</java.version>
<mysql-connector.version>8.0.33</mysql-connector.version>
<axon-starter.version>4.8.1</axon-starter.version>
<common.version>0.0.1-SNAPSHOT</common.version>
<common.version>1.0</common.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -49,7 +49,7 @@

<dependency>
<groupId>com.nashtech.common</groupId>
<artifactId>CommonService</artifactId>
<artifactId>Common</artifactId>
<version>${common.version}</version>
</dependency>

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

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

0 comments on commit b7d55e8

Please sign in to comment.