From 82e03978b89938219958032efb1448cc76baa181 Mon Sep 17 00:00:00 2001 From: Saumit Date: Sat, 27 Sep 2025 02:14:26 +0530 Subject: Initial snapshot - OpenTelemetry demo 2.1.3 -f --- .../pages/api/products/[productId]/index.ts | 26 ++++++++++++++++++++++ src/frontend/pages/api/products/index.ts | 26 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/frontend/pages/api/products/[productId]/index.ts create mode 100644 src/frontend/pages/api/products/index.ts (limited to 'src/frontend/pages/api/products') 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) => { + 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) => { + 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); -- cgit v1.2.3