diff options
Diffstat (limited to 'src/frontend/pages/api/products/index.ts')
| -rw-r--r-- | src/frontend/pages/api/products/index.ts | 26 |
1 files changed, 26 insertions, 0 deletions
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); |
