Files
gulermak_metro/app/api/settings/route.ts
Şahan Hasret 76c31274d5 Database
2025-11-21 17:46:30 +03:00

53 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 }
);
}
});
}