"feat: add product API with Prisma integration and update dependencies"
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,8 @@
|
||||
04_poc
|
||||
**/*del
|
||||
**/*bak
|
||||
**/*copy*
|
||||
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/node,python,nextjs
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=node,python,nextjs
|
||||
|
@@ -45,6 +45,7 @@
|
||||
"dayjs": "^1.11.13",
|
||||
"es-toolkit": "^1.33.0",
|
||||
"jose": "^6.0.10",
|
||||
"lodash": "^4.17.21",
|
||||
"next": "^14.2.26",
|
||||
"pg": "^8.16.0",
|
||||
"prisma": "^5.6.0",
|
||||
@@ -56,6 +57,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.23.0",
|
||||
"@types/lodash": "^4.17.17",
|
||||
"@types/node": "^22.13.13",
|
||||
"@types/react": "^18.3.20",
|
||||
"@types/react-dom": "^18.3.5",
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,25 +1,32 @@
|
||||
// src/app/api/product/details/route.ts
|
||||
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
import { logger } from 'src/utils/logger';
|
||||
import { STATUS, response, handleError } from 'src/utils/response';
|
||||
|
||||
import { _products } from 'src/_mock/_product';
|
||||
import prisma from '../../../lib/prisma';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
/** **************************************
|
||||
* Get product details
|
||||
*************************************** */
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = req.nextUrl;
|
||||
|
||||
// RULES: productId must exist
|
||||
const productId = searchParams.get('productId');
|
||||
if (!productId) {
|
||||
return response({ message: 'Product ID is required!' }, STATUS.BAD_REQUEST);
|
||||
}
|
||||
|
||||
const products = _products();
|
||||
|
||||
const product = products.find((productItem) => productItem.id === productId);
|
||||
// NOTE: productId confirmed exist, run below
|
||||
const product = await prisma.productItem.findFirst({
|
||||
include: { reviews: true },
|
||||
where: { id: productId },
|
||||
});
|
||||
|
||||
if (!product) {
|
||||
return response({ message: 'Product not found!' }, STATUS.NOT_FOUND);
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// src/app/api/product/list/route.ts
|
||||
import { logger } from 'src/utils/logger';
|
||||
import { STATUS, response, handleError } from 'src/utils/response';
|
||||
|
||||
|
@@ -780,6 +780,11 @@
|
||||
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz"
|
||||
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==
|
||||
|
||||
"@types/lodash@^4.17.17":
|
||||
version "4.17.17"
|
||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.17.tgz#fb85a04f47e9e4da888384feead0de05f7070355"
|
||||
integrity sha512-RRVJ+J3J+WmyOTqnz3PiBLA501eKwXl2noseKOrNo/6+XEHjTAxO4xHvxQB6QuNm+s4WRbn6rSiap8+EA+ykFQ==
|
||||
|
||||
"@types/node@^22.13.13":
|
||||
version "22.13.13"
|
||||
resolved "https://registry.npmjs.org/@types/node/-/node-22.13.13.tgz"
|
||||
@@ -2428,6 +2433,11 @@ lodash.merge@^4.6.2:
|
||||
resolved "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz"
|
||||
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
||||
|
||||
lodash@^4.17.21:
|
||||
version "4.17.21"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||
|
||||
loose-envify@^1.1.0, loose-envify@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz"
|
||||
|
Reference in New Issue
Block a user