Skip to content

Commit

Permalink
readme file added and code coverage completed
Browse files Browse the repository at this point in the history
  • Loading branch information
abidknashtech committed Jan 17, 2024
1 parent d92b260 commit 577700f
Show file tree
Hide file tree
Showing 48 changed files with 884 additions and 277 deletions.
Binary file added documentation/saga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions order-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ curl --location 'http://localhost:9090/orders/create' \
```
curl --location 'http://localhost:9090/orders/1652'
```

## Saga Orchestration
Saga orchestration is a design pattern in distributed systems where car-demo process is broken down into a series of smaller, independent transactions (sagas) that can be orchestrated to ensure consistency and reliability across the entire process.

![saga.png](..%2Fdocumentation%2Fsaga.png)
## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down
2 changes: 1 addition & 1 deletion order-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<sonar.organization>nashtech</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonarConfig>b47aeba29df2889126c736ee7012a5a490edc34a</sonarConfig> <!-- NOSONAR -->
<sonar.login>${sonarConfig}</sonar.login> <!-- NOSONAR -->
<sonar.token>${sonarConfig}</sonar.token> <!-- NOSONAR -->
<sonar.jacoco.reportPath>target/coverage-reports/jacoco.exec</sonar.jacoco.reportPath>
<sonar.coverage.exclusions>
**/*config*/**,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.nashtech.order;

import com.nashtech.order.commands.CreateOrderCommandInterceptor;
import com.nashtech.order.exception.handler.OrderServiceEventsErrorHandler;
import com.nashtech.order.commands.handler.CreateOrderCommandInterceptor;
import com.nashtech.order.exception.OrderServiceEventsErrorHandler;
import org.axonframework.commandhandling.CommandBus;
import org.axonframework.config.EventProcessingConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ public class OrderAggregate {

@AggregateIdentifier
private String orderId;
private String productId;
private String userId;
private String paymentId;
private String shipmentId;
private OrderStatus orderStatus;

private String reasonToRejectedOrder;
String productId;
String userId;
String paymentId;
String shipmentId;
OrderStatus orderStatus;
String reasonToRejectedOrder;

public OrderAggregate() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.nashtech.common.utils.OrderStatus;
import lombok.Builder;
import lombok.Value;
import lombok.Getter;
import org.axonframework.modelling.command.TargetAggregateIdentifier;

@Value
@Builder
@Getter
public class ApproveOrderCommand {
@TargetAggregateIdentifier
String orderId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.nashtech.order.commands;

import lombok.Builder;
import lombok.Value;
import lombok.Getter;
import org.axonframework.modelling.command.TargetAggregateIdentifier;

@Value
@Builder
@Getter
public class CreateOrderCommand {
@TargetAggregateIdentifier
String orderId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@

import com.nashtech.common.utils.OrderStatus;
import lombok.Builder;
import lombok.Value;
import lombok.Getter;
import org.axonframework.modelling.command.TargetAggregateIdentifier;

import java.util.Date;

@Value
@Builder
@Getter
public class RejectOrderCommand {
@TargetAggregateIdentifier
String orderId;
String userId;
String productId;
String paymentId;
String shipmentId;
Date timestamp = new Date();
String reasonToFailed;
String errorMessage;
OrderStatus orderStatus;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nashtech.order.commands;
package com.nashtech.order.commands.handler;

import com.nashtech.order.commands.CreateOrderCommand;
import com.nashtech.order.repository.OrderLookupRepository;
import com.nashtech.order.repository.entity.OrderLookupEntity;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.nashtech.common.utils.OrderStatus;
import lombok.Builder;
import lombok.Value;
import lombok.Getter;

@Value
@Getter
@Builder
public class OrderApprovedEvent {
String orderId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.nashtech.common.utils.OrderStatus;
import lombok.Builder;
import lombok.Value;
import lombok.Getter;

@Value
@Builder
@Getter
public class OrderCancelledEvent {
String orderId;
String productId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.nashtech.common.utils.OrderStatus;
import lombok.Builder;
import lombok.Value;
import lombok.Getter;

@Value
@Getter
@Builder
public class OrderCreatedEvent {
String orderId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.nashtech.order.exception;

import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Data
@NoArgsConstructor
@Setter
@Getter
public class CompensateOrder {
private String orderId;
private String userId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.nashtech.order.exception;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Date;

@Data
@AllArgsConstructor
@Getter
public class ErrorMessage {
private final Date timestamp;
private final String message;
private Date timestamp;
private String message;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nashtech.order.exception.handler;
package com.nashtech.order.exception;

import com.nashtech.order.exception.ErrorMessage;
import org.springframework.http.HttpHeaders;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nashtech.order.exception.handler;
package com.nashtech.order.exception;

import lombok.extern.slf4j.Slf4j;
import org.axonframework.eventhandling.EventMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void on(OrderCreatedEvent event) {

FailedOrderEntity failedOrder = new FailedOrderEntity();
failedOrder.setOrderId(event.getOrderId());
failedOrder.setTimestamp(new Date());
failedOrderRepository.save(failedOrder);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.nashtech.order.query;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class FindOrderQuery {
String orderId;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.nashtech.order.query;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Getter
public class FindOrdersByUserQuery {
String userId;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.nashtech.order.query;
package com.nashtech.order.query.handler;

import com.nashtech.order.query.FindOrdersByUserQuery;
import com.nashtech.order.repository.OrderRepository;
import com.nashtech.order.repository.entity.OrderEntity;
import org.axonframework.queryhandling.QueryHandler;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

@Data
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "failed_orders")
Expand All @@ -19,7 +19,7 @@ public class FailedOrderEntity {
private String productId;
private String paymentId;
private String shipmentId;
private Date timestamp = new Date();
private Date timestamp;
private String reasonToFailed;
private String orderStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class OrderEntity {
private String productId;
private String paymentId;
private String shipmentId;
private Date timestamp = new Date();
private Date timestamp;
private String orderStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;


@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -46,13 +47,6 @@ public OrderSummary createOrder(@Valid @RequestBody OrderCreateRequest orderRequ
.quantity(orderRequest.getQuantity()).orderId(orderId)
.build();

/* try (SubscriptionQueryResult<OrderSummary, OrderSummary> queryResult = queryGateway.subscriptionQuery(
new FindOrderQuery(orderId), ResponseTypes.instanceOf(OrderSummary.class),
ResponseTypes.instanceOf(OrderSummary.class))) {
commandGateway.send(createOrderCommand);
return queryResult.updates().blockFirst();
}*/

commandGateway.send(createOrderCommand);
return OrderSummary.builder()
.orderId(orderId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;

@Data
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.nashtech.order.restapi.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class OrderSummary {
private String orderId;
private String orderStatus;
Expand Down
Loading

0 comments on commit 577700f

Please sign in to comment.