Add version selector to /[locale]/search: new /api/bible/versions endpoint; fetch versions per locale; refetch books on version change; pass version to search API; localized label.

This commit is contained in:
andupetcu
2025-09-20 18:13:13 +03:00
parent a1b92be2a5
commit df0eb6661f
4 changed files with 73 additions and 2 deletions

View File

@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/db'
export const runtime = 'nodejs'
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const locale = (searchParams.get('locale') || 'ro').toLowerCase()
const langCandidates = Array.from(new Set([locale, locale.toLowerCase(), locale.toUpperCase()]))
const versions = await prisma.bibleVersion.findMany({
where: { language: { in: langCandidates } },
orderBy: [{ isDefault: 'desc' }, { name: 'asc' }]
})
return NextResponse.json({
success: true,
versions: versions.map(v => ({
id: v.id,
name: v.name,
abbreviation: v.abbreviation,
language: v.language,
isDefault: v.isDefault,
}))
})
} catch (error) {
console.error('Error fetching versions:', error)
return NextResponse.json({ success: false, versions: [] }, { status: 500 })
}
}