first commit
This commit is contained in:
41
app/api/list_channel/route.ts
Normal file
41
app/api/list_channel/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { auth } from '@/auth';
|
||||
import { PrismaClient } from '@/app/generated/prisma';
|
||||
|
||||
export async function GET() {
|
||||
const session = await auth();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const email = session.user?.email as string | undefined;
|
||||
if (!email) {
|
||||
return NextResponse.json({ error: '세션 이메일을 찾을 수 없습니다' }, { status: 400 });
|
||||
}
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
try {
|
||||
if (email === 'wsx204@naver.com') {
|
||||
const allHandles = await prisma.userHandle.findMany({
|
||||
orderBy: { createtime: 'desc' },
|
||||
select: { id: true, email: true, handle: true, isApproved: true, createtime: true, icon: true }
|
||||
});
|
||||
return NextResponse.json({ items: allHandles });
|
||||
}
|
||||
else{
|
||||
const handles = await prisma.userHandle.findMany({
|
||||
where: { email },
|
||||
orderBy: { createtime: 'desc' },
|
||||
select: { id: true, email: true, handle: true, isApproved: true, createtime: true, icon: true }
|
||||
});
|
||||
return NextResponse.json({ items: handles });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('list_channel 오류:', e);
|
||||
return NextResponse.json({ error: '조회 실패' }, { status: 500 });
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user