spring-boot-microservices-series-v2 icon indicating copy to clipboard operation
spring-boot-microservices-series-v2 copied to clipboard

While Creating Order, it should have all 3 values of orderItem as mandatory

Open rajadilipkolli opened this issue 2 years ago • 0 comments

Currently for creating a new Order we use below code,

public record OrderRequest(
        @Positive(message = "CustomerId should be positive") Long customerId,
        @NotEmpty(message = "Order without items not valid") List<OrderItemRequest> items) {}

we have validation set up at the Order (parent) level. However, we need to extend this validation to the OrderItem level (child) to ensure that all key attributes are properly validated.

Specifically, we need to enforce the following validation rules for OrderItemRequest:

  • Quantity should not be zero.
  • Price should not be zero.
  • A valid product code must be provided.

To implement this enhancement, the following tasks need to be completed:

  1. Modify OrderItemRequest.java : Add validation logic to the OrderItemRequest class to enforce the above-mentioned rules.
  2. Create a New JUnit : Develop a new test case in the OrderControllerIT.java class to demonstrate that the extended validation at the child level is functioning correctly. This test case should cover various scenarios to ensure thorough testing.

rajadilipkolli avatar Sep 18 '23 14:09 rajadilipkolli