## Social Media Management System - Add SocialMediaLink database model with platform, URL, icon, and ordering - Create complete CRUD API endpoints for admin social media management - Implement admin social media management page with Material-UI DataGrid - Add "Social Media" menu item to admin navigation - Update footer to dynamically load and display enabled social media links - Support multiple platforms: Facebook, Twitter, Instagram, YouTube, LinkedIn, GitHub, TikTok - Include proper icon mapping and fallback handling ## Admin Pages Improvements - Replace broken TinyMCE editor with working WYSIWYG rich text editor - Create SimpleRichEditor component with toolbar for formatting - Fix admin authentication to use cookies instead of localStorage tokens - Update all admin API calls to use credentials: 'include' - Increase content editor height to 800px for better editing experience - Add Lexical editor component as alternative (not currently used) ## Footer Pages System - Create 8 comprehensive footer pages: About, Blog, Support, API Docs, Terms, Privacy, Cookies, GDPR - Implement dynamic footer link management with smart categorization - Separate Quick Links and Legal sections with automatic filtering - Remove duplicate hardcoded links and use database-driven system - All footer pages are fully written with professional content ## Database & Dependencies - Add uuid package for ID generation - Update Prisma schema with new SocialMediaLink model and relations - Seed default social media links for Facebook, Twitter, Instagram, YouTube - Add Lexical rich text editor packages (@lexical/react, etc.) ## Technical Improvements - Fix async params compatibility for Next.js 15 - Update MUI DataGrid deprecated props - Improve admin layout navigation structure - Add proper TypeScript interfaces for all new components - Implement proper error handling and user feedback 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
113 lines
3.0 KiB
TypeScript
113 lines
3.0 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { prisma } from '@/lib/db'
|
|
|
|
// Ensure this route runs on the Node.js runtime (Prisma requires Node)
|
|
export const runtime = 'nodejs'
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
console.log('Books API called')
|
|
const { searchParams } = new URL(request.url)
|
|
const locale = searchParams.get('locale') || 'ro'
|
|
const versionId = searchParams.get('version') // Optional specific version ID
|
|
console.log('Locale:', locale, 'Version ID:', versionId)
|
|
|
|
// Get the appropriate Bible version
|
|
let bibleVersion
|
|
const langCandidates = Array.from(new Set([locale, locale.toLowerCase(), locale.toUpperCase()]))
|
|
if (versionId) {
|
|
// Use specific version if provided (no language filter needed)
|
|
bibleVersion = await prisma.bibleVersion.findFirst({
|
|
where: {
|
|
id: versionId
|
|
}
|
|
})
|
|
} else {
|
|
// Try default version for the language
|
|
bibleVersion = await prisma.bibleVersion.findFirst({
|
|
where: {
|
|
language: { in: langCandidates },
|
|
isDefault: true
|
|
}
|
|
})
|
|
// Fallback: any version for the language
|
|
if (!bibleVersion) {
|
|
bibleVersion = await prisma.bibleVersion.findFirst({
|
|
where: { language: { in: langCandidates } },
|
|
orderBy: { createdAt: 'asc' }
|
|
})
|
|
}
|
|
// Fallback: use English default if requested locale not found
|
|
if (!bibleVersion && locale !== 'en') {
|
|
bibleVersion = await prisma.bibleVersion.findFirst({
|
|
where: { language: 'en', isDefault: true }
|
|
})
|
|
}
|
|
}
|
|
|
|
if (!bibleVersion) {
|
|
return NextResponse.json({
|
|
success: false,
|
|
error: `No Bible version found for language: ${locale}`,
|
|
books: []
|
|
}, { status: 404 })
|
|
}
|
|
|
|
// Get books for this version
|
|
const books = await prisma.bibleBook.findMany({
|
|
where: {
|
|
versionId: bibleVersion.id
|
|
},
|
|
orderBy: {
|
|
orderNum: 'asc'
|
|
},
|
|
include: {
|
|
chapters: {
|
|
orderBy: {
|
|
chapterNum: 'asc'
|
|
},
|
|
include: {
|
|
_count: {
|
|
select: {
|
|
verses: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
version: {
|
|
id: bibleVersion.id,
|
|
name: bibleVersion.name,
|
|
abbreviation: bibleVersion.abbreviation,
|
|
language: bibleVersion.language
|
|
},
|
|
books: books.map(book => ({
|
|
id: book.id,
|
|
name: book.name,
|
|
testament: book.testament,
|
|
orderNum: book.orderNum,
|
|
bookKey: book.bookKey,
|
|
chapters: book.chapters.map(chapter => ({
|
|
id: chapter.id,
|
|
chapterNum: chapter.chapterNum,
|
|
verseCount: chapter._count.verses
|
|
}))
|
|
}))
|
|
})
|
|
} catch (error) {
|
|
console.error('Error fetching books:', error)
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: 'Failed to fetch books',
|
|
books: []
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|