feat: CMS com limites de caracteres, traduções auto e painel de notificações

This commit is contained in:
Erik
2025-11-27 12:05:23 -03:00
parent ea0c4ac5a6
commit 6e32ffdc95
40 changed files with 3665 additions and 278 deletions

View File

@@ -31,22 +31,33 @@ export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const slug = searchParams.get('slug');
const locale = searchParams.get('locale') || 'pt';
if (slug) {
// Buscar página específica
// Buscar página específica com locale
const page = await prisma.pageContent.findUnique({
where: { slug }
where: { slug_locale: { slug, locale } }
});
if (!page) {
// Fallback para PT se não encontrar
if (locale !== 'pt') {
const ptPage = await prisma.pageContent.findUnique({
where: { slug_locale: { slug, locale: 'pt' } }
});
if (ptPage) {
return NextResponse.json({ ...ptPage, fallback: true });
}
}
return NextResponse.json({ error: 'Página não encontrada' }, { status: 404 });
}
return NextResponse.json(page);
}
// Listar todas as páginas
// Listar todas as páginas (só PT para admin)
const pages = await prisma.pageContent.findMany({
where: { locale: 'pt' },
orderBy: { slug: 'asc' }
});
@@ -72,11 +83,11 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: 'Slug e conteúdo são obrigatórios' }, { status: 400 });
}
// Upsert: criar ou atualizar se já existir
// Upsert: criar ou atualizar se já existir (versão PT)
const page = await prisma.pageContent.upsert({
where: { slug },
where: { slug_locale: { slug, locale: 'pt' } },
update: { content },
create: { slug, content }
create: { slug, locale: 'pt', content }
});
return NextResponse.json({ success: true, page });