Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions V1java/order/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</parent>
<groupId>om</groupId>
<artifactId>order</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<name>order</name>
<description>order module for order management APIs</description>
<properties>
<java.version>21</java.version>
<java.version>24</java.version>
<spring-cloud.version>2023.0.1</spring-cloud.version>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* @GetExchange("/api/v1/inventory") from Spring 6 is used here, which is an alias to @HttpExchange(method = "GET")
*/
public interface InventoryClient {
@GetExchange("/api/v1/inventory")

@CircuitBreaker(name = "inventory", fallbackMethod = "fallbackMethod") //The name "inventory matches the circuit breaker name in application.properties"

@Retry(name = "inventory")
public abstract boolean isItemInStock(@RequestParam String skuCode, @RequestParam Integer quantityForQuery);

Expand Down
5 changes: 2 additions & 3 deletions V1java/order/src/main/java/om/order/config/Constants.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package om.order.config;

public abstract class Constants {

public static final String NEW_ORDER_PLACED_MSG = "An order has been created and placed.";
public static final String ORDER_PLACED_QUEUE_NAME = "order-placed";
public static final String NEW_ORDER_PLACED__MSG = "An order has been created and placed.";
public static final String ORDER_PLACED__QUEUE_NAME = "order-placed";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.context.annotation.Configuration;

/**
* Documentation of the API of Order module (microservice) using OpenAPI Specifications (OAS)
* Documentation of the API of Order module (microservice) using OpenAPI Specification (OAS)
*/
@Configuration
public class OpenApiSpecsConfig {
Expand All @@ -23,6 +23,6 @@ public OpenAPI OrderOasApi() {
> Inventory

Order microservice is for creating, listing, modifying and removing orders and order details. Its API has the base URI as "/api/v1/orders".
""").version("v1.0.0").contact(new Contact().name("Rishi Raj").url("https://bio.link/rishiraj49de")));
""").version("v1.0.0").contact(new Contact().name("Rishi Raj").url("https://www.linkedin.com/in/rishirajopenminds/")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class RestClientConfig {

@Bean
public InventoryClient inventoryClient(){
// * RestClient from Spring 6 is used here for synchronous client with fluent API.
// for non-blocking, reactive client, WebClient may be used.

/** RestClient from Spring 6 is used here for synchronous client with fluent API.
for non-blocking, reactive client, WebClient may be used. */
RestClient restClient = RestClient.builder()
.baseUrl(inventoryConnectUrl)
.requestFactory(getClientRequestFactory())
Expand All @@ -37,6 +38,5 @@ private ClientHttpRequestFactory getClientRequestFactory() {
.withConnectTimeout(Duration.ofSeconds(3))
.withReadTimeout(Duration.ofSeconds(3));
return ClientHttpRequestFactories.get(httpRequestFactorySettings);

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package om.order.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import om.order.config.Constants;
import om.order.dto.OrderReq;
import om.order.dto.OrderResp;
Expand All @@ -21,20 +19,20 @@

//@RequiredArgsConstructor
@RestController// @Slf4j
//@RequestMapping(value = "/api/orders",headers = "Accept-Version=v1") // A different scheme of API versioning
//@RequestMapping(value = "/api/orders",headers = "Accept-Version=v1") // A different scheme of API versioning, available to choose
@RequestMapping(value = "/api/v1/orders")
public class OrderController {
private final OrderService orderService;
public OrderController(OrderService orderService) {this.orderService = orderService;}
public OrderController(OrderService orderService) {this.orderService = orderService;}

// @ResponseStatus(HttpStatus.CREATED): the modern way to write Controller Endpoints.
// Older way is depicted in ResponseEntity<List<ProductResp>> ProductController.getAllProducts() endpoint.
/** @ResponseStatus(HttpStatus.CREATED): the modern way to write Controller Endpoints.
Older way is depicted in ResponseEntity<List<ProductResp>> ProductController.getAllProducts() endpoint.*/
@PostMapping
@ResponseStatus(HttpStatus.CREATED) // 201
public String createOrder(@Valid @RequestBody OrderReq orderReq) {
orderService.createOrder(orderReq);
//log.debug(Constants.NEW_ORDER_PLACED_MSG);
return Constants.NEW_ORDER_PLACED_MSG;
return Constants.NEW_ORDER_PLACED__MSG;
}

// getOrders()
Expand Down
3 changes: 1 addition & 2 deletions V1java/order/src/main/java/om/order/dao/OrderRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
import om.order.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;

public interface OrderRepo extends JpaRepository<Order,Long> {
}
public interface OrderRepo extends JpaRepository<Order,Long> {}
4 changes: 1 addition & 3 deletions V1java/order/src/main/java/om/order/dto/OrderReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

import java.math.BigDecimal;

public record OrderReq(String id, String orderNumber, String itemSkuCode,
BigDecimal pricePerItemUnit,Integer quantity,UserDetails userDetails) {
}
public record OrderReq(String id, String orderNumber, String itemSkuCode, BigDecimal pricePerItemUnit,Integer quantity,UserDetails userDetails) {}
4 changes: 1 addition & 3 deletions V1java/order/src/main/java/om/order/dto/OrderResp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

import java.math.BigDecimal;

public record OrderResp(String id, String orderNumber, String itemSkuCode,
BigDecimal pricePerItemUnit, Integer quantity, UserDetails userDetails) {
}
public record OrderResp(String id, String orderNumber, String itemSkuCode, BigDecimal pricePerItemUnit, Integer quantity, UserDetails userDetails) {}
2 changes: 1 addition & 1 deletion V1java/order/src/main/java/om/order/dto/UserDetails.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package om.order.dto;
public record UserDetails(String emailAddress, String name) {}

public record UserDetails(String emailAddress, String name) {}
12 changes: 10 additions & 2 deletions V1java/order/src/main/java/om/order/entity/Order.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package om.order.entity;

import jakarta.persistence.*;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.PastOrPresent;
Expand Down Expand Up @@ -29,6 +34,10 @@ public class Order {
@NotEmpty(message="Order number is mandatory.")
private String orderNumber;

private LocalDateTime orderDate;
private String status;
private BigDecimal totalAmount;

@Column(name="item_sku_code",nullable = false)
@NotEmpty(message="SKU code is mandatory.")
private String itemSkuCode;
Expand All @@ -47,5 +56,4 @@ public class Order {
@Column(name="updated",nullable = false)
@PastOrPresent(message = "Future record modification date/time is not permitted.")
private LocalDateTime updated;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package om.order.event;

public record OrderPlacedEventTemp(String OrderNumber,String emailAddress) { }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

import java.time.LocalDateTime;

public record ErrorDetails(LocalDateTime timestamp, String errMsg, String errDesc, String errCode) {
}
public record ErrorDetails(LocalDateTime timestamp, String errMsg, String errDesc, String errCode) { }
3 changes: 1 addition & 2 deletions V1java/order/src/main/resources/avro/order-placed.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"namespace":"om.notification.dto",
"fields": [
{"name":"orderNumber","type":"string"},
{"name":"emailAddress","type":"string"},
{"name":"name","type":"string"}
{"name":"emailAddress","type":"string"}
]
}
3 changes: 1 addition & 2 deletions V1java/order/src/test/avro/order-placed.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"namespace":"om.notification.dto",
"fields": [
{"name":"orderNumber","type":"string"},
{"name":"emailAddress","type":"string"},
{"name":"name","type":"string"}
{"name":"emailAddress","type":"string"}
]
}
12 changes: 5 additions & 7 deletions V1java/order/src/test/java/om/order/OrderApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void shouldSubmitOrder() {
"itemSkuCode":"DE342GES34233111",
"pricePerItemUnit":130.20,
"quantity":3,
"userDetails":{
"userDetails":{
"emailAddress":"rishiraj@emails.co",
"name":"Rishi Raj"
}
Expand All @@ -64,28 +64,26 @@ void shouldSubmitOrder() {
.extract()
.body().asString();

assertThat(responseBodyString, Matchers.is(Constants.NEW_ORDER_PLACED_MSG));
assertThat(responseBodyString, Matchers.is(Constants.NEW_ORDER_PLACED__MSG));
}

@Test
void shouldReturnAllOrders() {

}

@Test
void shouldReturnOrdersByUserEmail() {

}

@Test
void shouldReturnOrdersByUserName() {

}

@Test
void shouldReturnOrderByOrderNumber() {

}

@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public ProductResp addProduct(@RequestBody ProductReq productReq) {

@GetMapping
public ResponseEntity<List<ProductResp>> getAllProducts(@RequestParam(name="skuCode", required = false) String skuCode) {
//Dev Tools: Uncomment this code fragment to test timeout and retry with Resilience4j tooling
//Dev Tools: Uncomment the following code fragment to test timeout and retry with Resilience4j tooling

// For general application workflow, keep the below code fragment commented
/*if (0 == new Random().nextInt(2)) {
try {
Expand All @@ -58,7 +59,8 @@ public ResponseEntity<List<ProductResp>> getAllProducts(@RequestParam(name="skuC
throw new RuntimeException(e);
}
}*/
// Usual practice to add <Status Code> to Response

// Usual way to add <Status Code> to Response
return ResponseEntity.ok(productService.getAllProducts(skuCode));
}

Expand All @@ -67,10 +69,8 @@ public ResponseEntity<ProductResp> getProduct(@PathVariable("id") String id) {
return ResponseEntity.ok(productService.getProduct(id));
}


@PutMapping
public ResponseEntity<ProductResp> updatePriceOfProductFoundBySkuCode(@RequestBody ProductReq productReq) {
//public ResponseEntity<ProductResp> updatePriceOfProductFoundBySkuCode(@RequestParam String skuCode) {
//Dev Tools: Uncomment this code fragment to test timeout and retry with Resilience4j tooling
if (0 == new Random().nextInt(2)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.math.BigDecimal;

@JsonIgnoreProperties(ignoreUnknown=true)
public record ProductReq(String id,String name, String desc, String skuCode, BigDecimal pricePerItemUnit) {
}
7 changes: 4 additions & 3 deletions V1java/product/src/main/java/om/product/entity/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
@Builder @Data
@Document(value = "product")
public class Product {

@Id
private String id;

@NotEmpty(message="Product name is cannot be omitted.")
@NotEmpty(message="Product name cannot be omitted.")
private String name;
private String desc;

@NotEmpty(message="SKU code is mandatory.")
@NotEmpty(message="SKU code is cannot be omitted.")
private String skuCode; // Category may be inferred from SKU code
private String primaryCategory;
private BigDecimal pricePerItemUnit; //vendors and variants may be added optionally
private BigDecimal pricePerItemUnit; //vendors and variants may be added, if needed
private boolean inStock;
private LocalDate releaseDate;
private List<String> tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ public interface IProductService {
List<ProductResp> getAllProducts(String skuCode);
ProductResp getProduct(String id);
ProductResp updatePriceOfProductFoundBySkuCode(ProductReq productReq);
//ProductResp updatePriceOfProductFoundBySkuCode(String skuCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import om.product.exception.ProductNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
Expand All @@ -23,11 +24,11 @@ public class ProductServiceImpl implements IProductService {
@Autowired
private final ProductRepository productRepository;

@Override
@Override @Transactional
public ProductResp addProduct(ProductReq productReq) {
Product newProduct = Product.builder().name(productReq.name()).desc(productReq.desc()).skuCode(productReq.skuCode()).pricePerItemUnit(productReq.pricePerItemUnit()).build();
productRepository.save(newProduct);
log.info("New product has been added with id: {}", newProduct.getId());
log.info("New product has been added with Id: {}", newProduct.getId());
return mapToResponse(newProduct);
}

Expand All @@ -38,17 +39,21 @@ public List<ProductResp> getAllProducts(String skuCode) {
}
@Override
public ProductResp getProduct(String id) {
return productRepository.findAll().stream().filter(prod -> prod.getId().equals(id)).map(prod -> mapToResponse(prod)).findFirst().orElseThrow(()-> new ProductNotFoundException(id));
return productRepository.findAll().stream()
.filter(prod -> prod.getId().equals(id))
.map(prod -> mapToResponse(prod)).findFirst()
.orElseThrow(()-> new ProductNotFoundException(id));
}

@Override
@Override @Transactional
public ProductResp updatePriceOfProductFoundBySkuCode(ProductReq productReq) {
Optional<Product> matchingProductOpt = productRepository.findAll().stream().filter(prod -> prod.getSkuCode().equals(productReq.skuCode())).findFirst();
Optional<Product> matchingProductOpt = productRepository.findAll().stream()
.filter(prod -> prod.getSkuCode().equals(productReq.skuCode())).findFirst();

if(matchingProductOpt.isEmpty()) throw new ProductNotFoundException(productReq.skuCode());

Product matchingProduct = matchingProductOpt.get();
matchingProduct.setPricePerItemUnit(productReq.pricePerItemUnit());
return mapToResponse(
productRepository.save(matchingProduct)
);
return mapToResponse(productRepository.save(matchingProduct));
}
}
15 changes: 13 additions & 2 deletions snapshotV2kotlin/product/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
#########

# https://github.com/carlossg/docker-maven/blob/8cfe24baffa5b250f7bb2d31ce233fc28f3c4f20/amazoncorretto-21/Dockerfile
#FROM gradle:jdk21-corretto-al2023 AS build
# gradle:jdk21-corretto-al2023

# https://hub.docker.com/_/gradle
# https://github.com/gradle/docker-gradle/blob/ed0ea425043215ae106a8240ee86cb5f5e1ca5fb/jdk25-alpine/Dockerfile
#FROM gradle:9.2.1-jdk25-alpine AS build
#WORKDIR /app
#COPY ./src ./build.gradle.kts ./
#RUN gradle build

##########
# Deploy #
##########
# FROM amazoncorretto:21-alpine3.21 AS deploy


# openjdk 21 amazoncorretto - Official Image | Docker Hub
# https://hub.docker.com/_/amazoncorretto

FROM amazoncorretto:21-alpine3.21 AS deploy
# corretto-docker/25/jdk/alpine/3.22/Dockerfile at 5cf76cde46d4c2293a5d709e1e8630a334cb61c5 · corretto/corretto-docker
# https://github.com/corretto/corretto-docker/blob/5cf76cde46d4c2293a5d709e1e8630a334cb61c5/25/jdk/alpine/3.22/Dockerfile
FROM amazoncorretto:25.0.1-alpine AS deploy
WORKDIR /app
COPY ./src ./build.gradle.kts ./gradlew ./
RUN mkdir gradle
Expand Down
Loading
Loading