Initial commit: CMS completo com gerenciamento de leads e personalização de tema
This commit is contained in:
37
frontend/src/app/api/projects/route.ts
Normal file
37
frontend/src/app/api/projects/route.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user