"feat: add product API with Prisma integration and update dependencies"

This commit is contained in:
louiscklaw
2025-05-28 10:35:37 +08:00
parent efe70ceb69
commit 964ba3e5b0
6 changed files with 30 additions and 1070 deletions

View File

@@ -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);

View File

@@ -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';