Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/api/blog/route.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}
12 changes: 12 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ model User {

accounts Account[]
sessions Session[]
posts Post[]
}

model VerificationToken {
Expand All @@ -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
}