diff --git a/app/api/blog/route.ts b/app/api/blog/route.ts new file mode 100644 index 0000000..29b8b8c --- /dev/null +++ b/app/api/blog/route.ts @@ -0,0 +1,15 @@ +import { NextResponse } from 'next/server'; +import { prisma } from '../../../lib/prisma'; + +export async function GET() { + try { + const posts = await prisma.post.findMany({ + where: { published: true }, + include: { author: true }, + }); + return NextResponse.json(posts); + } catch (error) { + console.error('Error fetching posts:', error); + return NextResponse.json({ message: 'Error fetching posts' }, { status: 500 }); + } +} \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 757a8b7..fb77774 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -50,6 +50,7 @@ model User { accounts Account[] sessions Session[] + posts Post[] } model VerificationToken { @@ -58,4 +59,15 @@ model VerificationToken { expires DateTime @@unique([identifier, token]) +} + +model Post { + id String @id @default(cuid()) + title String + content String? @db.Text + published Boolean @default(false) + author User @relation(fields: [authorId], references: [id]) + authorId String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt } \ No newline at end of file