Add complete Biblical Guide web application with Material UI
Implemented comprehensive Romanian Biblical Guide web app: - Next.js 15 with App Router and TypeScript - Material UI 7.3.2 for modern, responsive design - PostgreSQL database with Prisma ORM - Complete Bible reader with book/chapter navigation - AI-powered biblical chat with Romanian responses - Prayer wall for community prayer requests - Advanced Bible search with filters and highlighting - Sample Bible data imported from API.Bible - All API endpoints created and working - Professional Material UI components throughout - Responsive layout with navigation and theme 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
34
app/api/bible/books/route.ts
Normal file
34
app/api/bible/books/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const books = await prisma.bibleBook.findMany({
|
||||
orderBy: {
|
||||
orderNum: 'asc'
|
||||
},
|
||||
include: {
|
||||
chapters: {
|
||||
orderBy: {
|
||||
chapterNum: 'asc'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
books: books
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching books:', error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Failed to fetch books',
|
||||
books: []
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
60
app/api/bible/chapter/route.ts
Normal file
60
app/api/bible/chapter/route.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { CacheManager } from '@/lib/cache'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const bookId = parseInt(searchParams.get('book') || '1')
|
||||
const chapterNum = parseInt(searchParams.get('chapter') || '1')
|
||||
|
||||
// Check cache first
|
||||
const cacheKey = CacheManager.getChapterKey(bookId, chapterNum)
|
||||
const cachedChapter = await CacheManager.get(cacheKey)
|
||||
|
||||
if (cachedChapter) {
|
||||
return NextResponse.json({
|
||||
chapter: JSON.parse(cachedChapter),
|
||||
cached: true
|
||||
})
|
||||
}
|
||||
|
||||
// Get chapter with verses from database
|
||||
const chapter = await prisma.bibleChapter.findFirst({
|
||||
where: {
|
||||
bookId,
|
||||
chapterNum
|
||||
},
|
||||
include: {
|
||||
verses: {
|
||||
orderBy: {
|
||||
verseNum: 'asc'
|
||||
}
|
||||
},
|
||||
book: true
|
||||
}
|
||||
})
|
||||
|
||||
if (!chapter) {
|
||||
return NextResponse.json({ error: 'Capitolul nu a fost găsit' }, { status: 404 })
|
||||
}
|
||||
|
||||
const chapterData = {
|
||||
id: chapter.id,
|
||||
bookName: chapter.book.name,
|
||||
chapterNum: chapter.chapterNum,
|
||||
verses: chapter.verses
|
||||
}
|
||||
|
||||
// Cache the result for 1 hour
|
||||
await CacheManager.set(cacheKey, JSON.stringify(chapterData), 3600)
|
||||
|
||||
return NextResponse.json({
|
||||
chapter: chapterData,
|
||||
cached: false
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Chapter fetch error:', error)
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
67
app/api/bible/search/route.ts
Normal file
67
app/api/bible/search/route.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const query = searchParams.get('q')
|
||||
const limit = parseInt(searchParams.get('limit') || '10')
|
||||
|
||||
if (!query) {
|
||||
return NextResponse.json({ error: 'Termenul de căutare este obligatoriu' }, { status: 400 })
|
||||
}
|
||||
|
||||
// Use full-text search function
|
||||
const results = await prisma.$queryRaw<Array<{
|
||||
verse_id: string
|
||||
book_name: string
|
||||
chapter_num: number
|
||||
verse_num: number
|
||||
verse_text: string
|
||||
rank: number
|
||||
}>>`
|
||||
SELECT * FROM search_verses(${query}, ${limit})
|
||||
`
|
||||
|
||||
return NextResponse.json({ results })
|
||||
} catch (error) {
|
||||
console.error('Search error:', error)
|
||||
|
||||
// Fallback to simple search if full-text search fails
|
||||
try {
|
||||
const fallbackResults = await prisma.bibleVerse.findMany({
|
||||
where: {
|
||||
text: {
|
||||
contains: query,
|
||||
mode: 'insensitive'
|
||||
}
|
||||
},
|
||||
include: {
|
||||
chapter: {
|
||||
include: {
|
||||
book: true
|
||||
}
|
||||
}
|
||||
},
|
||||
take: limit,
|
||||
orderBy: {
|
||||
id: 'asc'
|
||||
}
|
||||
})
|
||||
|
||||
const formattedResults = fallbackResults.map(verse => ({
|
||||
verse_id: verse.id,
|
||||
book_name: verse.chapter.book.name,
|
||||
chapter_num: verse.chapter.chapterNum,
|
||||
verse_num: verse.verseNum,
|
||||
verse_text: verse.text,
|
||||
rank: 0.5
|
||||
}))
|
||||
|
||||
return NextResponse.json({ results: formattedResults })
|
||||
} catch (fallbackError) {
|
||||
console.error('Fallback search error:', fallbackError)
|
||||
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
65
app/api/bible/verses/route.ts
Normal file
65
app/api/bible/verses/route.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const bookId = searchParams.get('bookId')
|
||||
const chapter = searchParams.get('chapter')
|
||||
|
||||
if (!bookId || !chapter) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Missing bookId or chapter parameter',
|
||||
verses: []
|
||||
},
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
// Find the chapter
|
||||
const chapterRecord = await prisma.bibleChapter.findFirst({
|
||||
where: {
|
||||
bookId: parseInt(bookId),
|
||||
chapterNum: parseInt(chapter)
|
||||
}
|
||||
})
|
||||
|
||||
if (!chapterRecord) {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
verses: []
|
||||
})
|
||||
}
|
||||
|
||||
// Get verses for this chapter
|
||||
const verses = await prisma.bibleVerse.findMany({
|
||||
where: {
|
||||
chapterId: chapterRecord.id
|
||||
},
|
||||
orderBy: {
|
||||
verseNum: 'asc'
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
verses: verses.map(verse => ({
|
||||
id: verse.id,
|
||||
verseNum: verse.verseNum,
|
||||
text: verse.text
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching verses:', error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Failed to fetch verses',
|
||||
verses: []
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user