From bcb392f172c8d1f75ef57fbfd9f403c0c99a81e0 Mon Sep 17 00:00:00 2001 From: Mahen Date: Mon, 9 Feb 2026 08:50:55 +0700 Subject: [PATCH] feat: integrate get review data endpoint to table --- src/app/api/review/route.ts | 48 ++++- src/components/dashboards/DashboardClient.tsx | 4 +- src/components/dashboards/ReviewTable.tsx | 172 ++++++++++++++---- src/components/ui/table.tsx | 34 +--- src/hooks/useReviewTable.ts | 29 +++ src/types/index.ts | 18 ++ 6 files changed, 229 insertions(+), 76 deletions(-) create mode 100644 src/hooks/useReviewTable.ts diff --git a/src/app/api/review/route.ts b/src/app/api/review/route.ts index babcd58..15ef817 100644 --- a/src/app/api/review/route.ts +++ b/src/app/api/review/route.ts @@ -6,19 +6,10 @@ export const dynamic = "force-dynamic"; export async function POST(request: Request) { try { - // const body = await request.json(); - - // const { name, brand } = body; - // if (!name || !brand) { - // return NextResponse.json( - // { error: "Missing required fields" }, - // { status: 400 }, - // ); - // } - const reviews = [ { productId: 2, + modelId: 1, content: "Laptop ini sangat ringan dan performanya cepat untuk kerja harian.", keywords: ["ringan", "cepat", "kerja"], @@ -27,6 +18,7 @@ export async function POST(request: Request) { }, { productId: 3, + modelId: 1, content: "Baterainya awet, tapi harganya cukup mahal.", keywords: ["baterai", "awet", "mahal"], sentiment: Sentiment.neutral, @@ -34,6 +26,7 @@ export async function POST(request: Request) { }, { productId: 4, + modelId: 1, content: "Performa kurang stabil dan sering panas.", keywords: ["performa", "panas", "stabil"], sentiment: Sentiment.negative, @@ -60,3 +53,38 @@ export async function POST(request: Request) { ); } } + +export async function GET() { + try { + const review = await prisma.review.findMany({ + orderBy: { + createdAt: "desc", + }, + select: { + id: true, + createdAt: true, + confidenceScore: true, + sentiment: true, + content: true, + keywords: true, + product: { + select: { + name: true, + brand: true, + }, + }, + }, + }); + + return NextResponse.json( + { + message: "Review data successfuly retrivied", + data: review, + }, + { status: 200 }, + ); + } catch (error) { + console.log(error); + return NextResponse.json({ message: "Error", data: [] }, { status: 500 }); + } +} diff --git a/src/components/dashboards/DashboardClient.tsx b/src/components/dashboards/DashboardClient.tsx index 8b43292..dc04876 100644 --- a/src/components/dashboards/DashboardClient.tsx +++ b/src/components/dashboards/DashboardClient.tsx @@ -1,4 +1,5 @@ "use client"; + import { Header } from "./Header"; import { MessageSquareText, @@ -28,7 +29,6 @@ export default function DashboardClient() { positiveCount, negativeCount, neutralCount, - filteredReviews, selectedBrand, loading, modelData, @@ -153,7 +153,7 @@ export default function DashboardClient() { onSelect={setSelectedBrand} /> - +