Database
This commit is contained in:
52
app/api/settings/route.ts
Normal file
52
app/api/settings/route.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { withAuth } from '@/lib/auth';
|
||||
|
||||
// GET - Site ayarlarını getir
|
||||
export async function GET() {
|
||||
try {
|
||||
const settings = await prisma.siteSettings.findFirst({
|
||||
where: { key: 'main' },
|
||||
});
|
||||
|
||||
if (!settings) {
|
||||
return NextResponse.json({ error: 'Ayarlar bulunamadı' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(JSON.parse(settings.value));
|
||||
} catch (error) {
|
||||
console.error('Settings fetch error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Ayarlar alınırken hata oluştu' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// POST - Site ayarlarını güncelle (Auth gerekli)
|
||||
export async function POST(request: NextRequest) {
|
||||
return withAuth(request, async () => {
|
||||
try {
|
||||
const data = await request.json();
|
||||
|
||||
const settings = await prisma.siteSettings.upsert({
|
||||
where: { key: 'main' },
|
||||
update: {
|
||||
value: JSON.stringify(data),
|
||||
},
|
||||
create: {
|
||||
key: 'main',
|
||||
value: JSON.stringify(data),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(JSON.parse(settings.value));
|
||||
} catch (error) {
|
||||
console.error('Settings update error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Ayarlar güncellenirken hata oluştu' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user