diff --git a/order-service/src/main/java/com/example/orderservice/entities/Order.java b/order-service/src/main/java/com/example/orderservice/entities/Order.java index d6070f3a..ebdd3806 100644 --- a/order-service/src/main/java/com/example/orderservice/entities/Order.java +++ b/order-service/src/main/java/com/example/orderservice/entities/Order.java @@ -13,6 +13,7 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.persistence.Version; import java.util.ArrayList; import java.util.List; import lombok.AllArgsConstructor; @@ -38,6 +39,8 @@ public class Order { private String source; + @Version private Long version; + @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) private List items = new ArrayList<>(); diff --git a/order-service/src/main/resources/db/changelog/migration/01-create_orders_table.xml b/order-service/src/main/resources/db/changelog/migration/01-create_orders_table.xml index dfb2b6c6..536b3c82 100644 --- a/order-service/src/main/resources/db/changelog/migration/01-create_orders_table.xml +++ b/order-service/src/main/resources/db/changelog/migration/01-create_orders_table.xml @@ -33,6 +33,7 @@ + diff --git a/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerIT.java b/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerIT.java index 8fec600f..0b2afc76 100644 --- a/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerIT.java +++ b/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerIT.java @@ -46,21 +46,27 @@ void setUp() { orderRepository.deleteAll(); orderList = new ArrayList<>(); - Order order1 = new Order(null, 1L, "NEW", null, new ArrayList<>()); + Order order1 = new Order(); + order1.setCustomerId(1L); + order1.setStatus("NEW"); OrderItem orderItem = new OrderItem(); orderItem.setProductId("Product1"); orderItem.setQuantity(10); orderItem.setProductPrice(BigDecimal.TEN); order1.addOrderItem(orderItem); this.orderList.add(order1); - Order order2 = new Order(null, 1L, "NEW", null, new ArrayList<>()); + Order order2 = new Order(); + order2.setCustomerId(1L); + order2.setStatus("NEW"); OrderItem orderItem1 = new OrderItem(); orderItem1.setProductId("Product2"); orderItem1.setQuantity(100); orderItem1.setProductPrice(BigDecimal.ONE); order2.addOrderItem(orderItem1); this.orderList.add(order2); - Order order3 = new Order(null, 1L, "NEW", null, new ArrayList<>()); + Order order3 = new Order(); + order3.setCustomerId(1L); + order3.setStatus("NEW"); OrderItem orderItem2 = new OrderItem(); orderItem2.setProductId("Product2"); orderItem2.setQuantity(100); diff --git a/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java b/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java index 6ee45a05..2b00ea35 100644 --- a/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java +++ b/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java @@ -197,7 +197,7 @@ void shouldUpdateOrder() throws Exception { void shouldReturn404WhenUpdatingNonExistingOrder() throws Exception { Long orderId = 1L; given(orderService.findOrderById(orderId)).willReturn(Optional.empty()); - Order order = new Order(1L, 1L, "CONFIRMED", null, new ArrayList<>()); + OrderRequest order = new OrderRequest(1L, new ArrayList<>()); this.mockMvc .perform(