project-standalo-sonic-cloud/app/api/discover/trending/route.ts

49 lines
1.1 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const limit = parseInt(searchParams.get('limit') || '20')
const songs = await prisma.song.findMany({
where: {
isPublic: true,
},
include: {
artist: {
select: {
id: true,
name: true,
slug: true,
avatarUrl: true,
verified: true,
},
},
album: {
select: {
id: true,
title: true,
slug: true,
coverUrl: true,
},
},
genres: {
include: {
genre: true,
},
},
},
orderBy: {
playCount: 'desc',
},
take: limit,
})
return NextResponse.json(songs)
} catch (error) {
console.error('Error fetching trending songs:', error)
return NextResponse.json({ error: 'Failed to fetch trending songs' }, { status: 500 })
}
}