From 95fcf99f4324ce303f11f3d6e22316a92ac2100c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Z=C4=85bek?= <120474310+DawidZabek@users.noreply.github.com> Date: Sat, 3 Jan 2026 18:04:49 +0100 Subject: [PATCH 1/4] Implement DELETE route for shopping list items --- app/api/shopping-list/[id]/route.ts | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/api/shopping-list/[id]/route.ts diff --git a/app/api/shopping-list/[id]/route.ts b/app/api/shopping-list/[id]/route.ts new file mode 100644 index 0000000..5e7edda --- /dev/null +++ b/app/api/shopping-list/[id]/route.ts @@ -0,0 +1,34 @@ +import { NextRequest, NextResponse } from "next/server"; +import { getSession } from "@/lib/auth"; +import prisma from "@/lib/prisma"; + +type Ctx = { + params: Promise<{ id: string }>; +}; + +export async function DELETE(_req: NextRequest, context: Ctx) { + const session = await getSession(); + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + + const { id } = await context.params; + const listId = Number(id); + + if (!Number.isFinite(listId)) { + return NextResponse.json({ error: "Invalid id" }, { status: 400 }); + } + + const list = await prisma.shoppingList.findUnique({ + where: { id: listId }, + select: { id: true, userId: true }, + }); + + if (!list || list.userId !== session.user.id) { + return NextResponse.json({ error: "Not found" }, { status: 404 }); + } + + await prisma.shoppingList.delete({ where: { id: listId } }); + + return NextResponse.json({ ok: true }, { status: 200 }); +} From e2c015f6728b0ff04bad5cb14acf9d31855534a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Z=C4=85bek?= <120474310+DawidZabek@users.noreply.github.com> Date: Sat, 3 Jan 2026 18:06:40 +0100 Subject: [PATCH 2/4] Refactor ShoppingListDetailPage component --- app/shopping-list/[id]/page.tsx | 80 ++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/app/shopping-list/[id]/page.tsx b/app/shopping-list/[id]/page.tsx index 6a216a4..db86c12 100644 --- a/app/shopping-list/[id]/page.tsx +++ b/app/shopping-list/[id]/page.tsx @@ -1,43 +1,73 @@ -import prisma from "@/lib/prisma" -import { getSession } from "@/lib/auth" +import prisma from "@/lib/prisma"; +import { getSession } from "@/lib/auth"; +import Link from "next/link"; type Props = { - params : Promise<{ id: string }> + params: Promise<{ id: string }>; +}; + +type ShoppingItem = { name: string; amount: number }; + +function formatDate(d: Date) { + return d.toISOString().slice(0, 10); } export default async function ShoppingListDetailPage({ params }: Props) { - const session = await getSession() - if (!session?.user?.id) return
Musisz być zalogowany
+ const session = await getSession(); + if (!session?.user?.id) returnMusisz być zalogowany
; - const corParams = await params - const id = parseInt(corParams.id, 10) - console.log("ID listy zakupów:", id) + const { id } = await params; + const listId = parseInt(id, 10); const list = await prisma.shoppingList.findUnique({ - where: { id }, - }) + where: { id: listId }, + }); if (!list || list.userId !== session.user.id) { - returnLista zakupów nie znaleziona
+ returnLista zakupów nie znaleziona
; } - const shoppingListItems = (list.items as { name: string; amount: number }[]) + const items = list.items as ShoppingItem[]; return ( -+ Zakres: {formatDate(list.startDate)} → {formatDate(list.endDate)} +
Brak produktów na liście.
+ ) : ( +Musisz być zalogowany
; + if (!session?.user?.id) returnMusisz być zalogowany
; const lists = await prisma.shoppingList.findMany({ where: { userId: session.user.id }, orderBy: { createdAt: "desc" }, }); - return ( -+ Wybierz listę, aby zobaczyć szczegóły. +
+Brak list zakupów. Wygeneruj nową listę zakupów.
++ Zakres dat +
++ Utworzono: {formatDate(list.createdAt)} +
+ +