Skip to content

Commit

Permalink
Merge pull request #43 from rishiraj88/develop
Browse files Browse the repository at this point in the history
Incident resolved: Add userDetails in orderReq body for API testing.
  • Loading branch information
rishiraj88 authored Feb 12, 2025
2 parents a2ae589 + 9ca7fd5 commit 2162456
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 34 deletions.
1 change: 0 additions & 1 deletion inventory/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 0 additions & 1 deletion order/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion order/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.4</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath/>
</parent>
<groupId>om</groupId>
<artifactId>order</artifactId>
Expand Down
10 changes: 4 additions & 6 deletions order/src/main/java/om/order/clients/InventoryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
/**
* to replicate the API of Inventory microservice
*/
@Slf4j
public abstract class InventoryClient {
@GetExchange("/api/inventory")
public interface InventoryClient {
@GetExchange("/api/v1/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());
default boolean fallbackMethod(String skuCode, Integer quantityForQuery, Throwable throwable) {
return false;
}
}
14 changes: 7 additions & 7 deletions order/src/main/java/om/order/service/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion order/src/test/java/om/order/OrderApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ void shouldSubmitOrder() {
"orderNumber":"DE3343INT432342342222",\s
"itemSkuCode":"DE342GES34233111",\s
"pricePerItem":130.20,
"quantity":3
"quantity":3,
"userDetails":{
"emailAddress":"rishiraj@emails.co",
"name":"Rishi Raj"
}
}""";

// Mock the dependency on Inventory API for checking the available quantity in stock
Expand Down
1 change: 0 additions & 1 deletion product/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import org.springframework.stereotype.Repository;

@Repository
public interface ProductRepo extends MongoRepository<Product,String> {
public interface ProductRepository extends MongoRepository<Product,String> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ProductResp> getAllProducts() {
List<Product> productList = productRepo.findAll();
return productList.stream().map(prod -> mapToResponse(prod)).collect(Collectors.toList());
return productRepository.findAll().stream().map(prod -> mapToResponse(prod)).collect(Collectors.toList());
}
}

0 comments on commit 2162456

Please sign in to comment.