project-standalo-sonic-cloud/app/api/artists/[id]/albums/route.ts

42 lines
905 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params
const albums = await prisma.album.findMany({
where: {
artistId: id,
},
include: {
artist: {
select: {
id: true,
name: true,
slug: true,
avatarUrl: true,
verified: true,
},
},
_count: {
select: {
songs: true,
},
},
},
orderBy: {
releaseDate: 'desc',
},
})
return NextResponse.json(albums)
} catch (error) {
console.error('Error fetching artist albums:', error)
return NextResponse.json({ error: 'Failed to fetch albums' }, { status: 500 })
}
}