From 663cf0f19eb8f05fa97075f30bed1a2aae0dd5ac Mon Sep 17 00:00:00 2001 From: koreacomp5 Date: Thu, 9 Oct 2025 16:40:53 +0900 Subject: [PATCH] =?UTF-8?q?6.5=20=EA=B0=9C=EC=9D=B8=ED=99=94=20=EC=9C=84?= =?UTF-8?q?=EC=A0=AF(=EC=B5=9C=EA=B7=BC=20=EB=B3=B8=20=EA=B8=80/=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EC=9A=94=EC=95=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/me/notifications/route.ts | 16 +++++++++++ src/app/api/me/recent/route.ts | 18 ++++++++++++ src/app/components/PersonalWidgets.tsx | 38 ++++++++++++++++++++++++++ src/app/page.tsx | 2 ++ 4 files changed, 74 insertions(+) create mode 100644 src/app/api/me/notifications/route.ts create mode 100644 src/app/api/me/recent/route.ts create mode 100644 src/app/components/PersonalWidgets.tsx diff --git a/src/app/api/me/notifications/route.ts b/src/app/api/me/notifications/route.ts new file mode 100644 index 0000000..03d44fd --- /dev/null +++ b/src/app/api/me/notifications/route.ts @@ -0,0 +1,16 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; +import { getUserIdFromRequest } from "@/lib/auth"; + +export async function GET(req: Request) { + const userId = getUserIdFromRequest(req); + if (!userId) return NextResponse.json({ items: [] }); + const items = await prisma.adminNotification.findMany({ + orderBy: { createdAt: "desc" }, + take: 5, + select: { id: true, type: true, message: true, createdAt: true }, + }); + return NextResponse.json({ items }); +} + + diff --git a/src/app/api/me/recent/route.ts b/src/app/api/me/recent/route.ts new file mode 100644 index 0000000..0a04d8d --- /dev/null +++ b/src/app/api/me/recent/route.ts @@ -0,0 +1,18 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; +import { getUserIdFromRequest } from "@/lib/auth"; + +export async function GET(req: Request) { + const userId = getUserIdFromRequest(req); + if (!userId) return NextResponse.json({ items: [] }); + const logs = await prisma.postViewLog.findMany({ + where: { userId }, + orderBy: { createdAt: "desc" }, + take: 10, + select: { postId: true, createdAt: true, post: { select: { title: true } } }, + }); + const items = logs.map((l) => ({ id: l.postId, title: l.post?.title ?? "", viewedAt: l.createdAt })); + return NextResponse.json({ items }); +} + + diff --git a/src/app/components/PersonalWidgets.tsx b/src/app/components/PersonalWidgets.tsx new file mode 100644 index 0000000..9e81330 --- /dev/null +++ b/src/app/components/PersonalWidgets.tsx @@ -0,0 +1,38 @@ +"use client"; +import useSWR from "swr"; + +type RecentItem = { id: string; title: string; viewedAt: string }; +type NotiItem = { id: string; type: string; message: string; createdAt: string }; + +const fetcher = (url: string) => fetch(url).then((r) => r.json()); + +export function PersonalWidgets() { + const { data: recent } = useSWR<{ items: RecentItem[] }>("/api/me/recent", fetcher); + const { data: notis } = useSWR<{ items: NotiItem[] }>("/api/me/notifications", fetcher); + return ( +
+
+

최근 본 글

+
    + {(recent?.items ?? []).map((i) => ( +
  • + {i.title} +
  • + ))} + {(!recent || recent.items.length === 0) &&
  • 최근 본 글이 없습니다.
  • } +
+
+
+

알림 요약

+
    + {(notis?.items ?? []).map((n) => ( +
  • {n.message}
  • + ))} + {(!notis || notis.items.length === 0) &&
  • 새 알림이 없습니다.
  • } +
+
+
+ ); +} + + diff --git a/src/app/page.tsx b/src/app/page.tsx index 415ef83..d31828b 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -2,6 +2,7 @@ import Image from "next/image"; import { QuickActions } from "@/app/components/QuickActions"; import { HeroBanner } from "@/app/components/HeroBanner"; import { PostList } from "@/app/components/PostList"; +import { PersonalWidgets } from "@/app/components/PersonalWidgets"; export default function Home({ searchParams }: { searchParams?: { sort?: "recent" | "popular" } }) { const sort = searchParams?.sort ?? "recent"; @@ -10,6 +11,7 @@ export default function Home({ searchParams }: { searchParams?: { sort?: "recent + ); }