import { NextRequest, NextResponse } from 'next/server' import prisma from '../../../../lib/prisma' type Params = { params: Promise<{ id: string }> } // GET /api/blog/[id] export async function GET( _request: NextRequest, context: { params: Promise<{ id: string }> } ): Promise { try { const { id } = await context.params const post = await prisma.blogPost.findUnique({ where: { id } }) if (!post) return NextResponse.json({ error: 'Non trouvé' }, { status: 404 }) return NextResponse.json(post) } catch (error) { console.error('GET /api/blog/[id] error:', error) return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 }) } } // PATCH /api/blog/[id] export async function PATCH( request: NextRequest, context: { params: Promise<{ id: string }> } ): Promise { try { const { id } = await context.params const body = await request.json() if (body.title && body.slug === undefined) { const { generateSlug } = await import('@/lib/utils') body.slug = generateSlug(body.title) } const post = await prisma.blogPost.update({ where: { id }, data: body }) return NextResponse.json(post) } catch (error) { console.error('PATCH /api/blog/[id] error:', error) return NextResponse.json({ error: 'Erreur lors de la mise à jour' }, { status: 500 }) } } // DELETE /api/blog/[id] export async function DELETE( _request: NextRequest, context: { params: Promise<{ id: string }> } ): Promise { try { const { id } = await context.params await prisma.blogPost.delete({ where: { id } }) return NextResponse.json({ success: true }) } catch (error) { console.error('DELETE /api/blog/[id] error:', error) return NextResponse.json({ error: 'Erreur lors de la suppression' }, { status: 500 }) } }