Skip to content

Commit 15b4c76

Browse files
authored
Merge pull request #55 from dockersamples/add-description-field
Add description field
2 parents dec36b5 + c0dc0e6 commit 15b4c76

File tree

7 files changed

+68
-26
lines changed

7 files changed

+68
-26
lines changed

demo/sdlc-e2e/demo.patch

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
diff --git a/src/services/ProductService.js b/src/services/ProductService.js
2-
index 85b9ecb..629bea9 100644
3-
--- a/src/services/ProductService.js
4-
+++ b/src/services/ProductService.js
5-
@@ -49,7 +49,6 @@ async function createProduct(product) {
6-
action: "product_created",
7-
id: newProductId,
8-
name: product.name,
9-
- upc: product.upc,
10-
price: product.price,
11-
});
12-
131
diff --git a/Dockerfile b/Dockerfile
14-
index 0577738..38d57d9 100644
2+
index 0577738..4932dda 100644
153
--- a/Dockerfile
164
+++ b/Dockerfile
175
@@ -5,7 +5,7 @@
@@ -23,18 +11,15 @@ index 0577738..38d57d9 100644
2311

2412
# Setup a non-root user to run the app
2513
WORKDIR /usr/local/app
26-
@@ -23,9 +23,9 @@ COPY --chown=appuser:appuser package.json package-lock.json ./
14+
@@ -23,7 +23,7 @@ COPY --chown=appuser:appuser package.json package-lock.json ./
2715
# and automatically restart the app.
2816
###########################################################
2917
FROM base AS dev
3018
-ENV NODE_ENV=development
3119
+ENV NODE_ENV development
3220
RUN npm install
33-
-CMD ["yarn", "dev-container"]
34-
+CMD ["npm", "run", "dev-container"]
35-
21+
CMD ["yarn", "dev-container"]
3622

37-
###########################################################
3823
@@ -35,10 +35,10 @@ CMD ["yarn", "dev-container"]
3924
# installs only the production dependencies.
4025
###########################################################
@@ -49,16 +34,17 @@ index 0577738..38d57d9 100644
4934
-CMD [ "node", "src/index.js" ]
5035
\ No newline at end of file
5136
+CMD node src/index.js
37+
\ No newline at end of file
5238
diff --git a/package-lock.json b/package-lock.json
53-
index d3706f8..0a0c834 100644
39+
index d3706f8..d0158a8 100644
5440
--- a/package-lock.json
5541
+++ b/package-lock.json
5642
@@ -10,7 +10,7 @@
5743
"dependencies": {
5844
"@aws-sdk/client-s3": "^3.651.1",
5945
"dotenv": "^16.4.5",
6046
- "express": "^4.21.1",
61-
+ "express": "4.17.1",
47+
+ "express": "^4.17.1",
6248
"kafkajs": "^2.2.4",
6349
"multer": "^1.4.5-lts.1",
6450
"node-fetch": "v2",
@@ -850,15 +836,27 @@ index d3706f8..0a0c834 100644
850836
"engines": {
851837
"node": ">=0.6"
852838
diff --git a/package.json b/package.json
853-
index 8438638..14bdcf1 100644
839+
index 8438638..9fa06d2 100644
854840
--- a/package.json
855841
+++ b/package.json
856842
@@ -16,7 +16,7 @@
857843
"dependencies": {
858844
"@aws-sdk/client-s3": "^3.651.1",
859845
"dotenv": "^16.4.5",
860846
- "express": "^4.21.1",
861-
+ "express": "4.17.1",
847+
+ "express": "^4.17.1",
862848
"kafkajs": "^2.2.4",
863849
"multer": "^1.4.5-lts.1",
864850
"node-fetch": "v2",
851+
diff --git a/src/services/ProductService.js b/src/services/ProductService.js
852+
index 31eaed7..a212fd8 100644
853+
--- a/src/services/ProductService.js
854+
+++ b/src/services/ProductService.js
855+
@@ -49,7 +49,6 @@ async function createProduct(product) {
856+
action: "product_created",
857+
id: newProductId,
858+
name: product.name,
859+
- upc: product.upc,
860+
price: product.price,
861+
description: product.description,
862+
});

dev/db/1-create-schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CREATE TABLE products (
22
id SERIAL PRIMARY KEY,
33
name VARCHAR(255) NOT NULL,
4+
description TEXT,
45
upc VARCHAR(12) NOT NULL UNIQUE,
56
price DECIMAL(10, 2) NOT NULL,
67
has_image BOOLEAN NOT NULL DEFAULT FALSE

dev/webapp/src/App.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback, useEffect, useState } from "react";
22
import "./App.css";
33
import { ProductRow } from "./ProductRow";
4+
import sampleProducts from "./sample-products.json";
45

56
function App() {
67
const [catalog, setCatalog] = useState(null);
@@ -21,11 +22,18 @@ function App() {
2122

2223
const createProduct = useCallback(() => {
2324
const body = {
24-
name: "New Product",
25-
price: 100,
25+
price: 100 + Math.floor(Math.random() * 100),
2626
upc: 100000000000 + catalog.length + 1,
2727
};
2828

29+
if (catalog.length < sampleProducts.length) {
30+
body.name = sampleProducts[catalog.length].name;
31+
body.description = sampleProducts[catalog.length].description;
32+
} else {
33+
body.name = `New Product #${catalog.length + 1}`;
34+
body.description = "A fancy description for an awesome product";
35+
}
36+
2937
fetch("/api/products", {
3038
method: "POST",
3139
headers: { "Content-Type": "application/json" },
@@ -57,6 +65,7 @@ function App() {
5765
<tr>
5866
<th>ID</th>
5967
<th>Name</th>
68+
<th>Description</th>
6069
<th>Price</th>
6170
<th>UPC</th>
6271
<th>Inventory</th>

dev/webapp/src/ProductRow.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function ProductRow({ product, onChange }) {
3333
<tr>
3434
<td>{product.id}</td>
3535
<td>{product.name}</td>
36+
<td>{product.description}</td>
3637
<td>{product.price}</td>
3738
<td>{product.upc}</td>
3839
<td>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"name": "Stellaris Dream Weaver",
4+
"description": "Capture the cosmos in your sleep. The Stellaris Dream Weaver uses subtle sonic frequencies and bioluminescent patterns to gently guide you into a deeply restful and vividly imaginative dream state. Features adjustable intensity levels and a calming lavender scent."
5+
},
6+
{
7+
"name": "Chronos Pocket Watch",
8+
"description": "A beautifully crafted antique pocket watch that doesn't tell time… exactly. The Chronos Pocket Watch subtly alters your perception of time, allowing you to savor moments longer and feel less rushed. (Note: Results may vary. Not recommended for time-sensitive activities.)"
9+
},
10+
{
11+
"name": "Lumina Bloom Terrarium",
12+
"description": "Bring a miniature, self-sustaining ecosystem to your desk. The Lumina Bloom Terrarium houses a variety of bioluminescent mosses and tiny, glowing fungi, creating a mesmerizing display that changes subtly throughout the day. Requires minimal maintenance."
13+
},
14+
{
15+
"name": "EchoStone Meditation Bracelet",
16+
"description": "Connect with your inner peace. The EchoStone Meditation Bracelet vibrates with a unique, personalized resonance, helping you center your thoughts and release tension. Choose from a range of gemstone combinations for different vibrational effects."
17+
},
18+
{
19+
"name": " Aetheria Sensory Quill",
20+
"description": "Unlock your creativity with the Aetheria Sensory Quill. This elegant writing instrument responds to your emotions, subtly altering its texture and ink flow to reflect your mood. Perfect for writers, artists, and anyone seeking a deeper connection to their creativity."
21+
}
22+
]

src/services/ProductService.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ async function createProduct(product) {
4040
throw new Error("Product with this UPC already exists");
4141

4242
const result = await client.query(
43-
"INSERT INTO products (name, upc, price) VALUES ($1, $2, $3) RETURNING id",
44-
[product.name, product.upc, product.price],
43+
"INSERT INTO products (name, upc, price, description) VALUES ($1, $2, $3, $4) RETURNING id",
44+
[product.name, product.upc, product.price, product.description],
4545
);
4646
const newProductId = result.rows[0].id;
4747

@@ -51,6 +51,7 @@ async function createProduct(product) {
5151
name: product.name,
5252
upc: product.upc,
5353
price: product.price,
54+
description: product.description,
5455
});
5556

5657
return {

test/integration/productCreation.integration.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,20 @@ describe("Product creation", () => {
5050
it("should publish and return a product when creating a product", async () => {
5151
const product = await productService.createProduct({
5252
name: "Test Product",
53+
description: "Test product description",
5354
price: 100,
5455
upc: "100000000001",
5556
});
5657

5758
expect(product.id).toBeDefined();
5859
expect(product.name).toBe("Test Product");
5960
expect(product.price).toBe(100);
61+
expect(product.description).toBe("Test product description");
6062

6163
const retrievedProduct = await productService.getProductById(product.id);
6264
expect(retrievedProduct.id).toBe(product.id);
6365
expect(retrievedProduct.name).toBe(product.name);
66+
expect(retrievedProduct.description).toBe(product.description);
6467
expect(retrievedProduct.inventory).toEqual({
6568
error: true,
6669
message: "Failed to get inventory",
@@ -70,12 +73,16 @@ describe("Product creation", () => {
7073
it("should publish a Kafka message when creating a product", async () => {
7174
createdProduct = await productService.createProduct({
7275
name: "Kafka publishing test",
76+
description: "Kafka publishing test description",
7377
price: 100,
7478
upc: "100000000002",
7579
});
7680

7781
expect(createdProduct.id).toBeDefined();
7882
expect(createdProduct.name).toBe("Kafka publishing test");
83+
expect(createdProduct.description).toBe(
84+
"Kafka publishing test description",
85+
);
7986
expect(createdProduct.price).toBe(100);
8087
expect(createdProduct.upc).toBe("100000000002");
8188

@@ -88,6 +95,7 @@ describe("Product creation", () => {
8895
it("should upload a file correctly", async () => {
8996
createdProduct = await productService.createProduct({
9097
name: "Kafka publishing test",
98+
description: "Kafka publishing test description",
9199
price: 100,
92100
upc: "100000000004",
93101
});
@@ -123,13 +131,15 @@ describe("Product creation", () => {
123131
it("doesn't allow duplicate UPCs", async () => {
124132
await productService.createProduct({
125133
name: "Kafka publishing test",
134+
description: "Kafka publishing test description",
126135
price: 100,
127136
upc: "100000000003",
128137
});
129138

130139
await expect(
131140
productService.createProduct({
132141
name: "Kafka publishing test",
142+
description: "Kafka publishing test description",
133143
price: 100,
134144
upc: "100000000003",
135145
}),

0 commit comments

Comments
 (0)