Skip to content

Commit

Permalink
auto generate product id
Browse files Browse the repository at this point in the history
  • Loading branch information
tkeburia committed Dec 11, 2023
1 parent 08b5d9e commit 983d4e8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ There are 4 services described in the diagram below

![high level architecture](./docs/arch.png)

1. Product-service - uses the GCP NoSQL Data store to persist the product catalog. The products can be queried as a list and new products can be created through the api endpoint.
2. Order-service - takes a request of a list of order line items, checks they are all in stock (http call to the inventory service) and if so, creates an order entry in the database. Afterwards it sends an event to notificationTopic kafka topic.
3. Inventory-service - takes a request for a product and checks whether it's in stock
4. Notification-service - listens to the notificationTopic topic and prints out a message every time an order comes through
1. **Product-service** - uses the GCP NoSQL Data store to persist the product catalog. The products can be queried as a list and new products can be created through the api endpoint.
2. **Order-service** - takes a request of a list of order line items, checks they are all in stock (http call to the inventory service) and if so, creates an order entry in the database. Afterwards it sends an event to notificationTopic kafka topic.
3. **Inventory-service** - takes a request for a product and checks whether it's in stock
4. **Notification-service** - listens to the notificationTopic topic and prints out a message every time an order comes through

## CI/CD

Expand Down Expand Up @@ -55,3 +55,30 @@ Some of them are:
* Set up for local runs (e.g. docker-compose file)
* More granular CI (individual builds/deployments depending on what changed)
* Clean-up/better modularisation of terraform

## Sample requests

Create an order

```shell
curl --location --request POST 'http://${ORDER_SERVICE_INGRESS_IP}/api/order' \
--header 'Content-Type: application/json' \
--data-raw '{
"orderLineItemsDtoList": [
{
"id": "123",
"skuCode": "iphone_13",
"price": 200,
"quantity": 1
}
]
}'
```

get all products in the catalog

```shell
curl http://${PRODUCT_SERVICE_INGRESS_IP}/api/product
```

create a new product
4 changes: 4 additions & 0 deletions product-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ public static void main(String[] args) {
public void run(String... args) {
if (productRepository.count() < 1) {
productRepository.save(Product.builder()
.id(123)
.name("iPhone 13")
.description("New iPhone")
.price(1000)
.skuCode("iphone_13")
.build()
);
productRepository.save(Product.builder()
.id(234)
.name("Samsung S23")
.description("New Samsung")
.price(800)
.skuCode("samsung_s23")
.build()
);
productRepository.save(Product.builder()
.id(345)
.name("Google Pixel 8")
.description("New Pixel")
.price(7000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@AllArgsConstructor
@NoArgsConstructor
public class ProductResponse {
private long id;
private String name;
private String description;
private int price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import org.springframework.cloud.gcp.data.datastore.core.mapping.Field;
import org.springframework.data.annotation.Id;

import java.math.BigDecimal;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

@Entity(name = "products")
@AllArgsConstructor
Expand All @@ -18,6 +19,7 @@
public class Product {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Field(name = "product_id")
private long id;
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public List<ProductResponse> getAllProducts() {

private ProductResponse mapToProductResponse(Product product) {
return ProductResponse.builder()
.id(product.getId())
.name(product.getName())
.description(product.getDescription())
.price(product.getPrice())
Expand Down

0 comments on commit 983d4e8

Please sign in to comment.