54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { createClient } from '@/lib/supabase/server'
|
|
import { PrismaClient } from '@prisma/client'
|
|
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
// GET /api/channels/[slug]/followers - Get channel followers
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{ params }: { params: { slug: string } }
|
|
) {
|
|
try {
|
|
const channel = await prisma.channel.findUnique({
|
|
where: { slug: params.slug },
|
|
include: {
|
|
followers: {
|
|
select: {
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
displayName: true,
|
|
avatarUrl: true,
|
|
},
|
|
},
|
|
followDate: true,
|
|
},
|
|
orderBy: { followDate: 'desc' },
|
|
take: 20,
|
|
},
|
|
_count: {
|
|
select: { followers: true },
|
|
},
|
|
},
|
|
})
|
|
|
|
if (!channel) {
|
|
return NextResponse.json({ error: 'Channel not found' }, { status: 404 })
|
|
}
|
|
|
|
return NextResponse.json(
|
|
{
|
|
followers: channel.followers,
|
|
totalFollowers: channel._count.followers,
|
|
},
|
|
{ status: 200 }
|
|
)
|
|
} catch (error) {
|
|
console.error('Error fetching followers:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch followers' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|