38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import prisma from '@/lib/prisma';
|
|
|
|
export async function GET() {
|
|
try {
|
|
const projects = await prisma.project.findMany({
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
return NextResponse.json(projects);
|
|
} catch (error) {
|
|
console.error('Error fetching projects:', error);
|
|
return NextResponse.json({ error: 'Error fetching projects' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const data = await request.json();
|
|
const project = await prisma.project.create({
|
|
data: {
|
|
title: data.title,
|
|
category: data.category,
|
|
client: data.client,
|
|
status: data.status,
|
|
completionDate: data.completionDate ? new Date(data.completionDate) : null,
|
|
description: data.description,
|
|
coverImage: data.coverImage,
|
|
galleryImages: data.galleryImages,
|
|
featured: data.featured,
|
|
},
|
|
});
|
|
return NextResponse.json(project);
|
|
} catch (error) {
|
|
console.error('Error creating project:', error);
|
|
return NextResponse.json({ error: 'Error creating project' }, { status: 500 });
|
|
}
|
|
}
|