diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-18 07:52:02 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-18 07:52:02 +0000 |
| commit | 48a2255bfc45ffcfb0b39ffefdd57cbacf8b36df (patch) | |
| tree | 0c88b7c126138233875e8d372a4e999e49c38a62 /app/api/notifications/route.ts | |
| parent | 2ef02e27dbe639876fa3b90c30307dda183545ec (diff) | |
(대표님) 파일관리변경, 클라IP추적, 실시간알림, 미들웨어변경, 알림API
Diffstat (limited to 'app/api/notifications/route.ts')
| -rw-r--r-- | app/api/notifications/route.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/app/api/notifications/route.ts b/app/api/notifications/route.ts new file mode 100644 index 00000000..cab0b74e --- /dev/null +++ b/app/api/notifications/route.ts @@ -0,0 +1,37 @@ +// app/api/notifications/route.ts +import { NextRequest, NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth'; +import { getUserNotifications,getUnreadNotificationCount } from '@/lib/notification/service'; +import { authOptions } from "@/app/api/auth/[...nextauth]/route" + + +export async function GET(request: NextRequest) { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + } + + const { searchParams } = new URL(request.url); + const limit = parseInt(searchParams.get('limit') || '20'); + const offset = parseInt(searchParams.get('offset') || '0'); + const unreadOnly = searchParams.get('unreadOnly') === 'true'; + + const [notifications, unreadCount] = await Promise.all([ + getUserNotifications(session.user.id, { limit, offset, unreadOnly }), + getUnreadNotificationCount(session.user.id) + ]); + + return NextResponse.json({ + notifications, + unreadCount, + hasMore: notifications.length === limit + }); + } catch (error) { + console.error('Error fetching notifications:', error); + return NextResponse.json( + { error: 'Failed to fetch notifications' }, + { status: 500 } + ); + } +}
\ No newline at end of file |
