save avant prochaine modif
This commit is contained in:
27
app/api/blog/route.ts
Normal file
27
app/api/blog/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
// GET /api/blog
|
||||
export async function GET() {
|
||||
try {
|
||||
const posts = await prisma.blogPost.findMany({
|
||||
orderBy: { date: 'desc' },
|
||||
})
|
||||
return NextResponse.json(posts)
|
||||
} catch (error) {
|
||||
console.error('GET /api/blog error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/blog
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const post = await prisma.blogPost.create({ data: body })
|
||||
return NextResponse.json(post, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('POST /api/blog error:', error)
|
||||
return NextResponse.json({ error: 'Erreur lors de la création' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user