From dd4ea5558b96a738bbafd32c9cfd47b2bed3b989 Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Tue, 11 Feb 2025 16:47:02 +0100 Subject: [PATCH 1/7] Rename the Repository for Product. --- product/Dockerfile | 1 - .../dao/{ProductRepo.java => ProductRepository.java} | 2 +- .../main/java/om/product/service/ProductServiceImpl.java | 9 ++++----- 3 files changed, 5 insertions(+), 7 deletions(-) rename product/src/main/java/om/product/dao/{ProductRepo.java => ProductRepository.java} (71%) diff --git a/product/Dockerfile b/product/Dockerfile index c3c5636..af17c4c 100644 --- a/product/Dockerfile +++ b/product/Dockerfile @@ -17,7 +17,6 @@ LABEL description="Dockerfile for Order-Manager::Product with JDK 21 and MongoDB COPY --from=build /app/target/product-1.0.1-SNAPSHOT.jar /app/target/ EXPOSE 8080 -#ENTRYPOINT [ "java", "-jar","target/product-1.0.1-SNAPSHOT.jar" ] CMD [ "java", "-jar","target/product-1.0.1-SNAPSHOT.jar" ] diff --git a/product/src/main/java/om/product/dao/ProductRepo.java b/product/src/main/java/om/product/dao/ProductRepository.java similarity index 71% rename from product/src/main/java/om/product/dao/ProductRepo.java rename to product/src/main/java/om/product/dao/ProductRepository.java index bcaf870..f837f12 100644 --- a/product/src/main/java/om/product/dao/ProductRepo.java +++ b/product/src/main/java/om/product/dao/ProductRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface ProductRepo extends MongoRepository { +public interface ProductRepository extends MongoRepository { } diff --git a/product/src/main/java/om/product/service/ProductServiceImpl.java b/product/src/main/java/om/product/service/ProductServiceImpl.java index 8ceed35..20efd37 100644 --- a/product/src/main/java/om/product/service/ProductServiceImpl.java +++ b/product/src/main/java/om/product/service/ProductServiceImpl.java @@ -2,7 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import om.product.dao.ProductRepo; +import om.product.dao.ProductRepository; import om.product.dto.ProductReq; import om.product.dto.ProductResp; import om.product.entity.Product; @@ -19,19 +19,18 @@ @Service public class ProductServiceImpl implements IProductService { @Autowired - private final ProductRepo productRepo; + private final ProductRepository productRepository; @Override public ProductResp addProduct(ProductReq productReq) { Product newProduct = Product.builder().name(productReq.name()).desc(productReq.desc()).skuCode(productReq.skuCode()).pricePerItem(productReq.pricePerItem()).build(); - productRepo.save(newProduct); + productRepository.save(newProduct); log.info("New product has been added with id: {}", newProduct.getId()); return mapToResponse(newProduct); } @Override public List getAllProducts() { - List productList = productRepo.findAll(); - return productList.stream().map(prod -> mapToResponse(prod)).collect(Collectors.toList()); + return productRepository.findAll().stream().map(prod -> mapToResponse(prod)).collect(Collectors.toList()); } } From cbcd24730e0fa3eeb52f38303d5a3558b7593b19 Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Tue, 11 Feb 2025 19:31:57 +0100 Subject: [PATCH 2/7] Update log messages. --- order/Dockerfile | 1 - order/pom.xml | 2 +- .../java/om/order/clients/InventoryClient.java | 2 +- .../java/om/order/service/OrderServiceImpl.java | 14 +++++++------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/order/Dockerfile b/order/Dockerfile index 982a45e..d4a7b28 100644 --- a/order/Dockerfile +++ b/order/Dockerfile @@ -17,7 +17,6 @@ LABEL description="Dockerfile for Order-Manager::Order with JDK 21, Confluent Ka COPY --from=build /app/target/order-1.0.1-SNAPSHOT.jar /app/target/ EXPOSE 8080 -#ENTRYPOINT [ "java", "-jar","target/order-1.0.1-SNAPSHOT.jar" ] CMD [ "java", "-jar","target/order-1.0.1-SNAPSHOT.jar" ] VOLUME ./mysql:/var/lib/mysql diff --git a/order/pom.xml b/order/pom.xml index 47dbff3..951bee6 100644 --- a/order/pom.xml +++ b/order/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent 3.2.4 - + om order diff --git a/order/src/main/java/om/order/clients/InventoryClient.java b/order/src/main/java/om/order/clients/InventoryClient.java index 53e9120..cecfc2d 100644 --- a/order/src/main/java/om/order/clients/InventoryClient.java +++ b/order/src/main/java/om/order/clients/InventoryClient.java @@ -14,7 +14,7 @@ public abstract class InventoryClient { @GetExchange("/api/inventory") @CircuitBreaker(name = "inventory", fallbackMethod = "fallbackMethod") @Retry(name = "inventory") - public abstract boolean isInStock(@RequestParam String skuCode, @RequestParam Integer quantityForQuery); + public abstract boolean isItemInStock(@RequestParam String skuCode, @RequestParam Integer quantityForQuery); boolean fallbackMethod(String skuCode, Integer quantityForQuery, Throwable throwable) { log.info("Sufficient quantity of SKU {} not found in inventory. Reason: {}", skuCode, throwable.getMessage()); diff --git a/order/src/main/java/om/order/service/OrderServiceImpl.java b/order/src/main/java/om/order/service/OrderServiceImpl.java index 3c1ee41..06893c8 100644 --- a/order/src/main/java/om/order/service/OrderServiceImpl.java +++ b/order/src/main/java/om/order/service/OrderServiceImpl.java @@ -23,8 +23,8 @@ public class OrderServiceImpl implements IOrderService { @Override public void createOrder(OrderReq orderReq) { - if(inventoryClient.isInStock(orderReq.itemSkuCode(),orderReq.quantity())) { - log.debug("The requested items are available in inventory."); + if(inventoryClient.isItemInStock(orderReq.itemSkuCode(),orderReq.quantity())) { + log.debug("The requested item quantity is available in inventory."); Order newOrder = Order.builder() .id(UUID.randomUUID().toString()) .orderNumber(orderReq.orderNumber()) @@ -36,14 +36,14 @@ public void createOrder(OrderReq orderReq) { // Send success message to message queue (with Kafka tooling) /* The following services among others may consume the message out of the queue for respective processes: :: Analytics service, - :: Dashboard service, and - :: Fraud detection service - :: Invoicing and Taxation service. + :: Dashboard service, + :: Fraud detection service, and + :: Invoicing & Taxation service. */ OrderPlacedEvent orderPlacedEvent = new OrderPlacedEvent(newOrder.getOrderNumber(),orderReq.userDetails().emailAddress()); - log.info("Sending the details of new order {} to 'order-placed' queue...",orderPlacedEvent); + log.info("Placing the details of new order {} into the queue: 'order-placed'...",orderPlacedEvent); kafkaTemplate.send(Constants.orderPlacedQueueName,orderPlacedEvent); - log.info("Sent the details of new order {} to 'order-placed' queue.", orderPlacedEvent); + log.info("Placed the details of new order {} into the queue: 'order-placed'.", orderPlacedEvent); } else { throw new InventoryShortOfStockException(orderReq.itemSkuCode(), orderReq.quantity()); From 87483a96bcafc5d437338fd41a4135371f41314f Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Tue, 11 Feb 2025 19:56:25 +0100 Subject: [PATCH 3/7] Edit log messages, comments and OpenAPI (Swagger) documentation. --- inventory/Dockerfile | 1 - .../src/main/java/om/inventory/InventoryApplication.java | 4 ++-- .../main/java/om/inventory/config/OpenApiSpecsConfig.java | 4 ++-- .../java/om/inventory/controller/InventoryController.java | 2 +- .../src/main/java/om/inventory/svc/IInventoryService.java | 2 +- .../main/java/om/inventory/svc/InventoryServiceImpl.java | 8 ++++---- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/inventory/Dockerfile b/inventory/Dockerfile index 9f5c19d..f7af29f 100644 --- a/inventory/Dockerfile +++ b/inventory/Dockerfile @@ -17,7 +17,6 @@ LABEL description="Dockerfile for Order-Manager::Inventory with JDK 21 and MySQL COPY --from=build /app/target/inventory-1.0.1-SNAPSHOT.jar /app/target/ EXPOSE 8080 -#ENTRYPOINT [ "java", "-jar","target/inventory-1.0.1-SNAPSHOT.jar" ] CMD [ "java", "-jar","target/inventory-1.0.1-SNAPSHOT.jar" ] VOLUME ./mysql:/var/lib/mysql diff --git a/inventory/src/main/java/om/inventory/InventoryApplication.java b/inventory/src/main/java/om/inventory/InventoryApplication.java index 8b93a3f..427e73f 100644 --- a/inventory/src/main/java/om/inventory/InventoryApplication.java +++ b/inventory/src/main/java/om/inventory/InventoryApplication.java @@ -4,9 +4,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication @Slf4j +@SpringBootApplication +@Slf4j public class InventoryApplication { - public static void main(String[] args) { SpringApplication.run(InventoryApplication.class, args); } diff --git a/inventory/src/main/java/om/inventory/config/OpenApiSpecsConfig.java b/inventory/src/main/java/om/inventory/config/OpenApiSpecsConfig.java index fe2df88..e25a605 100644 --- a/inventory/src/main/java/om/inventory/config/OpenApiSpecsConfig.java +++ b/inventory/src/main/java/om/inventory/config/OpenApiSpecsConfig.java @@ -19,7 +19,7 @@ public OpenAPI InventoryOasApi() { > Inventory - Inventory microservice is for checking whether there is enough quantity available in inventory stock in order to place a new item order. Its API has its base URI as "/api/inventory". - """).version("v1.0.0").contact(new Contact().name("Rishi Raj").url("https://bio.link/rishiraj49de"))); + Inventory microservice is for checking whether there is enough quantity of specified items available in inventory stock so as to fulfill a new order. Its API has the base URI as "/api/v1/inventory". + """).version("v1.0.1").contact(new Contact().name("Rishi Raj").url("https://bio.link/rishiraj49de"))); } } diff --git a/inventory/src/main/java/om/inventory/controller/InventoryController.java b/inventory/src/main/java/om/inventory/controller/InventoryController.java index ddc9d81..27fd3ea 100644 --- a/inventory/src/main/java/om/inventory/controller/InventoryController.java +++ b/inventory/src/main/java/om/inventory/controller/InventoryController.java @@ -20,6 +20,6 @@ public class InventoryController { @ResponseStatus(HttpStatus.OK) public boolean isInStock(@RequestParam String skuCode, @RequestParam Integer quantityForQuery) { log.info("Retrieving inventory stock details for the product SKU: "+ skuCode); - return inventoryService.isInStock(skuCode, quantityForQuery); + return inventoryService.isItemInStock(skuCode, quantityForQuery); } } diff --git a/inventory/src/main/java/om/inventory/svc/IInventoryService.java b/inventory/src/main/java/om/inventory/svc/IInventoryService.java index 31cd8e6..71edbd2 100644 --- a/inventory/src/main/java/om/inventory/svc/IInventoryService.java +++ b/inventory/src/main/java/om/inventory/svc/IInventoryService.java @@ -1,4 +1,4 @@ package om.inventory.svc; -public interface IInventoryService {public boolean isInStock(String itemSkuCode,Integer quantityToCheck); +public interface IInventoryService {public boolean isItemInStock(String itemSkuCode,Integer quantityToCheck); } diff --git a/inventory/src/main/java/om/inventory/svc/InventoryServiceImpl.java b/inventory/src/main/java/om/inventory/svc/InventoryServiceImpl.java index cf0313f..ddb3165 100644 --- a/inventory/src/main/java/om/inventory/svc/InventoryServiceImpl.java +++ b/inventory/src/main/java/om/inventory/svc/InventoryServiceImpl.java @@ -10,16 +10,16 @@ public class InventoryServiceImpl implements IInventoryService { private final InventoryRepo inventoryRepo; - public boolean isInStock(String itemSkuCode, Integer quantityToCheck) { + public boolean isItemInStock(String itemSkuCode, Integer quantityToCheck) { if (quantityToCheck > 0) { boolean available = inventoryRepo.existsByItemSkuCodeAndQuantityInStockIsGreaterThanEqual(itemSkuCode, quantityToCheck); if(available) - log.info("SUCCESS: The requested quantity of " + itemSkuCode + " is available for preparing the requested order."); + log.info("SUCCESS: The requested quantity of the item (SKU: " + itemSkuCode + ") is available for preparing the requested order."); else - log.info("FAILURE: The product SKU " + itemSkuCode + " is out of stock."); + log.info("FAILURE: The product item with SKU " + itemSkuCode + " is out of stock."); return available; } - log.info("ERROR: Kindly query with a decent quantity. Non-positive quantities are not good for checking the stock availability."); + log.info("ERROR: Kindly place the next request with a decent quantity. Non-positive quantities are not acceptable at this moment."); return false; } } From 21f962a8fbd5790b9495bdedad8fa74457ecc775 Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Tue, 11 Feb 2025 21:02:27 +0100 Subject: [PATCH 4/7] Update InventoryClient in Order app. --- order/src/main/java/om/order/clients/InventoryClient.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/order/src/main/java/om/order/clients/InventoryClient.java b/order/src/main/java/om/order/clients/InventoryClient.java index cecfc2d..f11692f 100644 --- a/order/src/main/java/om/order/clients/InventoryClient.java +++ b/order/src/main/java/om/order/clients/InventoryClient.java @@ -9,15 +9,13 @@ /** * to replicate the API of Inventory microservice */ -@Slf4j -public abstract class InventoryClient { +public interface InventoryClient { @GetExchange("/api/inventory") @CircuitBreaker(name = "inventory", fallbackMethod = "fallbackMethod") @Retry(name = "inventory") public abstract boolean isItemInStock(@RequestParam String skuCode, @RequestParam Integer quantityForQuery); - boolean fallbackMethod(String skuCode, Integer quantityForQuery, Throwable throwable) { - log.info("Sufficient quantity of SKU {} not found in inventory. Reason: {}", skuCode, throwable.getMessage()); + default boolean fallbackMethod(String skuCode, Integer quantityForQuery, Throwable throwable) { return false; } } From 7d621af3f737edec9f1ed752cd3360b0df3cf2ca Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Wed, 12 Feb 2025 08:51:43 +0100 Subject: [PATCH 5/7] Fix the request URI for Inventory API. --- order/src/main/java/om/order/clients/InventoryClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/order/src/main/java/om/order/clients/InventoryClient.java b/order/src/main/java/om/order/clients/InventoryClient.java index f11692f..65c74b0 100644 --- a/order/src/main/java/om/order/clients/InventoryClient.java +++ b/order/src/main/java/om/order/clients/InventoryClient.java @@ -10,7 +10,7 @@ * to replicate the API of Inventory microservice */ public interface InventoryClient { - @GetExchange("/api/inventory") + @GetExchange("/api/v1/inventory") @CircuitBreaker(name = "inventory", fallbackMethod = "fallbackMethod") @Retry(name = "inventory") public abstract boolean isItemInStock(@RequestParam String skuCode, @RequestParam Integer quantityForQuery); From f30c5e93352274c90e373c22ff7d631eb2e538e7 Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Wed, 12 Feb 2025 09:05:45 +0100 Subject: [PATCH 6/7] Add the userDetails JSON in orderRequest for API testing.. --- order/src/test/java/om/order/OrderApplicationTests.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/order/src/test/java/om/order/OrderApplicationTests.java b/order/src/test/java/om/order/OrderApplicationTests.java index ae7f326..a974fe8 100644 --- a/order/src/test/java/om/order/OrderApplicationTests.java +++ b/order/src/test/java/om/order/OrderApplicationTests.java @@ -41,7 +41,12 @@ void shouldSubmitOrder() { "orderNumber":"DE3343INT432342342222",\s "itemSkuCode":"DE342GES34233111",\s "pricePerItem":130.20, - "quantity":3 + "quantity":3, + "userDetails": + { + "emailAddress":"rishiraj@emails.co",\s + "name":"Rishi Raj",\s + } }"""; // Mock the dependency on Inventory API for checking the available quantity in stock From 9ca7fd5e2ef772ec061aec6cb8b2afcd003a47b2 Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Wed, 12 Feb 2025 09:13:37 +0100 Subject: [PATCH 7/7] Add the userDetails JSON in orderRequest for API testing.. --- order/src/test/java/om/order/OrderApplicationTests.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/order/src/test/java/om/order/OrderApplicationTests.java b/order/src/test/java/om/order/OrderApplicationTests.java index a974fe8..3db6170 100644 --- a/order/src/test/java/om/order/OrderApplicationTests.java +++ b/order/src/test/java/om/order/OrderApplicationTests.java @@ -42,10 +42,9 @@ void shouldSubmitOrder() { "itemSkuCode":"DE342GES34233111",\s "pricePerItem":130.20, "quantity":3, - "userDetails": - { - "emailAddress":"rishiraj@emails.co",\s - "name":"Rishi Raj",\s + "userDetails":{ + "emailAddress":"rishiraj@emails.co", + "name":"Rishi Raj" } }""";