project-standalo-sonic-cloud/app/api/songs/[id]/play/route.ts

30 lines
673 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params
const song = await prisma.song.update({
where: { id },
data: {
playCount: {
increment: 1,
},
},
select: {
id: true,
playCount: true,
},
})
return NextResponse.json(song)
} catch (error) {
console.error('Error incrementing play count:', error)
return NextResponse.json({ error: 'Failed to increment play count' }, { status: 500 })
}
}