Files
biblical-guide.com/app/api/prayers/route.ts
andupetcu 3b375c869b 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>
2025-09-20 14:10:28 +03:00

161 lines
4.8 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
const createPrayerSchema = z.object({
title: z.string().min(1).max(200),
description: z.string().min(1).max(1000),
category: z.enum(['personal', 'family', 'health', 'work', 'ministry', 'world']),
author: z.string().optional().default('Anonim')
})
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const category = searchParams.get('category')
const limit = parseInt(searchParams.get('limit') || '20')
// Mock prayer data for now
// TODO: Replace with actual database queries
const allPrayers = [
{
id: '1',
title: 'Rugăciune pentru vindecare',
description: 'Te rog să te rogi pentru tatăl meu care se află în spital. Are nevoie de vindecarea lui Dumnezeu.',
category: 'health',
author: 'Maria P.',
timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000),
prayerCount: 23,
isPrayedFor: false,
},
{
id: '2',
title: 'Îndrumarea lui Dumnezeu în carieră',
description: 'Caut direcția lui Dumnezeu pentru următorul pas în cariera mea. Te rog să te rogi pentru claritate și pace.',
category: 'work',
author: 'Alexandru M.',
timestamp: new Date(Date.now() - 5 * 60 * 60 * 1000),
prayerCount: 15,
isPrayedFor: true,
},
{
id: '3',
title: 'Unitatea în familia noastră',
description: 'Rugați-vă pentru restaurarea relațiilor în familia noastră și pentru iertarea reciprocă.',
category: 'family',
author: 'Anonim',
timestamp: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000),
prayerCount: 41,
isPrayedFor: false,
},
{
id: '4',
title: 'Pentru misionarii din Africa',
description: 'Rugați-vă pentru protecția și proviziunea pentru misionarii noștri care lucrează în Africa.',
category: 'ministry',
author: 'Pavel R.',
timestamp: new Date(Date.now() - 6 * 60 * 60 * 1000),
prayerCount: 12,
isPrayedFor: false,
},
{
id: '5',
title: 'Pace în Ucraina',
description: 'Să ne rugăm pentru pace și protecție pentru poporul ucrainean în aceste timpuri dificile.',
category: 'world',
author: 'Comunitatea',
timestamp: new Date(Date.now() - 12 * 60 * 60 * 1000),
prayerCount: 89,
isPrayedFor: true,
},
{
id: '6',
title: 'Trecerea prin depresie',
description: 'Am nevoie de rugăciuni pentru a trece prin această perioadă grea de depresie și anxietate.',
category: 'personal',
author: 'Anonim',
timestamp: new Date(Date.now() - 8 * 60 * 60 * 1000),
prayerCount: 34,
isPrayedFor: false,
}
]
let filteredPrayers = allPrayers
// Apply category filter
if (category && category !== 'all') {
filteredPrayers = allPrayers.filter(prayer => prayer.category === category)
}
// Apply limit
filteredPrayers = filteredPrayers.slice(0, limit)
// Sort by timestamp (newest first)
filteredPrayers.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime())
return NextResponse.json({
success: true,
prayers: filteredPrayers,
total: filteredPrayers.length
})
} catch (error) {
console.error('Error fetching prayers:', error)
return NextResponse.json(
{
success: false,
error: 'Failed to fetch prayers',
prayers: []
},
{ status: 500 }
)
}
}
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const validatedData = createPrayerSchema.parse(body)
// Create new prayer object
const newPrayer = {
id: Date.now().toString(),
title: validatedData.title,
description: validatedData.description,
category: validatedData.category,
author: validatedData.author,
timestamp: new Date(),
prayerCount: 0,
isPrayedFor: false,
}
// TODO: Save to database
// For now, just return the created prayer
console.log('New prayer created:', newPrayer)
return NextResponse.json({
success: true,
prayer: newPrayer,
message: 'Prayer request submitted successfully'
}, { status: 201 })
} catch (error) {
console.error('Error creating prayer:', error)
if (error instanceof z.ZodError) {
return NextResponse.json(
{
success: false,
error: 'Invalid prayer data',
details: error.errors
},
{ status: 400 }
)
}
return NextResponse.json(
{
success: false,
error: 'Failed to create prayer request'
},
{ status: 500 }
)
}
}