import { NextRequest, NextResponse } from 'next/server'; import { prisma } from '@/lib/prisma'; export async function GET(request: NextRequest) { try { // In a real app, you would check for admin session here // For now, we trust the 'x-admin-request' header if it's set by the server-side component or middleware // but typically you'd verify the session cookie/token const contacts = await prisma.contact.findMany({ orderBy: { createdAt: 'desc', }, take: 100, }); return NextResponse.json({ contacts }); } catch (error) { console.error('Error fetching contacts:', error); return NextResponse.json( { error: 'Failed to fetch contacts' }, { status: 500 } ); } }