aethex.live/app/api/channels/[slug]/followers/route.ts
2026-02-12 22:26:34 +00:00

55 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: Promise<{ slug: string }> }
) {
try {
const { slug } = await params
const channel = await prisma.channel.findUnique({
where: { 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 }
)
}
}