summaryrefslogtreecommitdiff
path: root/src/frontend/pages/api/products
diff options
context:
space:
mode:
authorSaumit <justsaumit@protonmail.com>2025-09-27 02:14:26 +0530
committerSaumit <justsaumit@protonmail.com>2025-09-27 02:14:26 +0530
commit82e03978b89938219958032efb1448cc76baa181 (patch)
tree626f3e54d52ecd49be0ed3bee30abacc0453d081 /src/frontend/pages/api/products
Initial snapshot - OpenTelemetry demo 2.1.3 -f
Diffstat (limited to 'src/frontend/pages/api/products')
-rw-r--r--src/frontend/pages/api/products/[productId]/index.ts26
-rw-r--r--src/frontend/pages/api/products/index.ts26
2 files changed, 52 insertions, 0 deletions
diff --git a/src/frontend/pages/api/products/[productId]/index.ts b/src/frontend/pages/api/products/[productId]/index.ts
new file mode 100644
index 0000000..eb62465
--- /dev/null
+++ b/src/frontend/pages/api/products/[productId]/index.ts
@@ -0,0 +1,26 @@
+// Copyright The OpenTelemetry Authors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { NextApiRequest, NextApiResponse } from 'next';
+import InstrumentationMiddleware from '../../../../utils/telemetry/InstrumentationMiddleware';
+import { Empty, Product } from '../../../../protos/demo';
+import ProductCatalogService from '../../../../services/ProductCatalog.service';
+
+type TResponse = Product | Empty;
+
+const handler = async ({ method, query }: NextApiRequest, res: NextApiResponse<TResponse>) => {
+ switch (method) {
+ case 'GET': {
+ const { productId = '', currencyCode = '' } = query;
+ const product = await ProductCatalogService.getProduct(productId as string, currencyCode as string);
+
+ return res.status(200).json(product);
+ }
+
+ default: {
+ return res.status(405).send('');
+ }
+ }
+};
+
+export default InstrumentationMiddleware(handler);
diff --git a/src/frontend/pages/api/products/index.ts b/src/frontend/pages/api/products/index.ts
new file mode 100644
index 0000000..74b8937
--- /dev/null
+++ b/src/frontend/pages/api/products/index.ts
@@ -0,0 +1,26 @@
+// Copyright The OpenTelemetry Authors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { NextApiRequest, NextApiResponse } from 'next';
+import InstrumentationMiddleware from '../../../utils/telemetry/InstrumentationMiddleware';
+import { Empty, Product } from '../../../protos/demo';
+import ProductCatalogService from '../../../services/ProductCatalog.service';
+
+type TResponse = Product[] | Empty;
+
+const handler = async ({ method, query }: NextApiRequest, res: NextApiResponse<TResponse>) => {
+ switch (method) {
+ case 'GET': {
+ const { currencyCode = '' } = query;
+ const productList = await ProductCatalogService.listProducts(currencyCode as string);
+
+ return res.status(200).json(productList);
+ }
+
+ default: {
+ return res.status(405).send('');
+ }
+ }
+};
+
+export default InstrumentationMiddleware(handler);