Bug fixed and preparing for OutBox Pattern For Transaction Management.
This commit is contained in:
@@ -13,7 +13,9 @@ import com.food.order.sysyem.valueobject.*;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.food.order.system.domain.entity.Order.FAILURE_MESSAGE_DELIMITER;
|
import static com.food.order.system.domain.entity.Order.FAILURE_MESSAGE_DELIMITER;
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ public class OrderDataAccessMapper {
|
|||||||
orderEntity.setAddress(deliveryAddressToAddressEntity(order.getDeliveryAddress()));
|
orderEntity.setAddress(deliveryAddressToAddressEntity(order.getDeliveryAddress()));
|
||||||
orderEntity.setPrice(order.getPrice().getAmount());
|
orderEntity.setPrice(order.getPrice().getAmount());
|
||||||
orderEntity.setItems(orderItemsToOrderItemsEntity(order.getItems()));
|
orderEntity.setItems(orderItemsToOrderItemsEntity(order.getItems()));
|
||||||
orderEntity.setFailureMessages(order.getFailureMessages() != null ?
|
orderEntity.setFailureMessages(Objects.nonNull(order.getFailureMessages()) ?
|
||||||
String.join(FAILURE_MESSAGE_DELIMITER, order.getFailureMessages()) : "");
|
String.join(FAILURE_MESSAGE_DELIMITER, order.getFailureMessages()) : "");
|
||||||
orderEntity.getAddress().setOrder(orderEntity);
|
orderEntity.getAddress().setOrder(orderEntity);
|
||||||
orderEntity.getItems().forEach(item -> item.setOrderEntity(orderEntity));
|
orderEntity.getItems().forEach(item -> item.setOrderEntity(orderEntity));
|
||||||
@@ -47,9 +49,9 @@ public class OrderDataAccessMapper {
|
|||||||
.items(orderItemsEntityToOrderItems(orderEntity.getItems()))
|
.items(orderItemsEntityToOrderItems(orderEntity.getItems()))
|
||||||
.trackingId(new TrackingId(orderEntity.getTrackingId()))
|
.trackingId(new TrackingId(orderEntity.getTrackingId()))
|
||||||
.status(orderEntity.getOrderStatus())
|
.status(orderEntity.getOrderStatus())
|
||||||
.failureMessages(orderEntity.getFailureMessages() != null ?
|
.failureMessages(Objects.isNull(orderEntity.getFailureMessages()) ? new ArrayList<>() :
|
||||||
List.of(orderEntity.getFailureMessages().split(FAILURE_MESSAGE_DELIMITER)) :
|
new ArrayList<>(Arrays.asList(orderEntity.getFailureMessages()
|
||||||
new ArrayList<>())
|
.split(FAILURE_MESSAGE_DELIMITER))))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class Order extends AggregateRoot<OrderId> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void cancel(List<String> failureMessages){
|
public void cancel(List<String> failureMessages){
|
||||||
if(Objects.equals(status, OrderStatus.CANCELLING) || Objects.equals(status, OrderStatus.PENDING))
|
if(!(Objects.equals(status, OrderStatus.CANCELLING) || Objects.equals(status, OrderStatus.PENDING)))
|
||||||
throw new OrderDomainException("Order status is not correct for cancel operation !");
|
throw new OrderDomainException("Order status is not correct for cancel operation !");
|
||||||
status = OrderStatus.CANCELLED;
|
status = OrderStatus.CANCELLED;
|
||||||
updateFailureMessages(failureMessages);
|
updateFailureMessages(failureMessages);
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ public class OrderDomainServiceImpl implements OrderDomainService {
|
|||||||
.forEach(orderItem -> restaurant.getProducts().forEach(restaurantProduct -> {
|
.forEach(orderItem -> restaurant.getProducts().forEach(restaurantProduct -> {
|
||||||
var currentProduct = orderItem.getProduct();
|
var currentProduct = orderItem.getProduct();
|
||||||
if(currentProduct.equals(restaurantProduct)){
|
if(currentProduct.equals(restaurantProduct)){
|
||||||
currentProduct.updateWithConfirmedNameAndPrice(restaurantProduct.getName(),restaurantProduct.getPrice());
|
currentProduct.updateWithConfirmedNameAndPrice(restaurantProduct.getName(),
|
||||||
|
restaurantProduct.getPrice());
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ AS
|
|||||||
p.id AS product_id,
|
p.id AS product_id,
|
||||||
p.name AS product_name,
|
p.name AS product_name,
|
||||||
p.price AS product_price,
|
p.price AS product_price,
|
||||||
p.available AS product_available,
|
p.available AS product_active
|
||||||
r.active AS product_active
|
|
||||||
FROM restaurant.restaurants r,
|
FROM restaurant.restaurants r,
|
||||||
restaurant.products p,
|
restaurant.products p,
|
||||||
restaurant.restaurant_products rp
|
restaurant.restaurant_products rp
|
||||||
|
|||||||
Reference in New Issue
Block a user