Move Add Prayer button to sidebar and implement comprehensive prayer functionality

- Integrated prayer data with Prisma database schema
- Updated API endpoints to use actual database
- Implemented AI prayer generation with Azure OpenAI
- Added user authentication for prayer creation
- Moved Add Prayer button from FAB to sidebar top
- Added prayer count tracking and user prayer status

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
andupetcu
2025-09-21 23:17:20 +03:00
parent 6492601355
commit 5a3c6a6691
7 changed files with 669 additions and 259 deletions

94
scripts/seed-prayers.ts Normal file
View File

@@ -0,0 +1,94 @@
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
console.log('Seeding prayer requests...')
const prayers = [
{
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 și de putere pentru a trece prin această perioadă dificilă.',
category: 'health',
author: 'Maria P.',
isAnonymous: false,
prayerCount: 23
},
{
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 în luarea acestei decizii importante.',
category: 'work',
author: 'Alexandru M.',
isAnonymous: false,
prayerCount: 15
},
{
title: 'Unitatea în familia noastră',
description: 'Rugați-vă pentru restaurarea relațiilor în familia noastră și pentru iertarea reciprocă. Avem nevoie de vindecarea rănilor din trecut.',
category: 'family',
author: 'Anonim',
isAnonymous: true,
prayerCount: 41
},
{
title: 'Pentru misionarii din Africa',
description: 'Rugați-vă pentru protecția și proviziunea pentru misionarii noștri care lucrează în Africa de Vest, în special pentru familia Popescu.',
category: 'ministry',
author: 'Pavel R.',
isAnonymous: false,
prayerCount: 12
},
{
title: 'Pace în Ucraina',
description: 'Să ne rugăm pentru pace și protecție pentru poporul ucrainean în aceste timpuri dificile. Pentru familiile despărțite și pentru cei care suferă.',
category: 'world',
author: 'Comunitatea',
isAnonymous: false,
prayerCount: 89
},
{
title: 'Trecerea prin depresie',
description: 'Am nevoie de rugăciuni pentru a trece prin această perioadă grea de depresie și anxietate. Cred că Dumnezeu poate să mă vindece.',
category: 'personal',
author: 'Anonim',
isAnonymous: true,
prayerCount: 34
},
{
title: 'Protecție pentru copiii noștri',
description: 'Rugați-vă pentru protecția copiilor noștri la școală și pentru înțelepciune în creșterea lor în credință.',
category: 'family',
author: 'Elena și Mihai',
isAnonymous: false,
prayerCount: 28
},
{
title: 'Vindecare de cancer',
description: 'Sora mea a fost diagnosticată cu cancer. Credem în puterea vindecătoare a lui Dumnezeu și avem nevoie de susținerea voastră în rugăciune.',
category: 'health',
author: 'Andreea S.',
isAnonymous: false,
prayerCount: 67
}
]
for (const prayer of prayers) {
await prisma.prayerRequest.create({
data: {
...prayer,
isActive: true
}
})
}
console.log('Prayer requests seeded successfully!')
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})

141
scripts/test-prayers.ts Normal file
View File

@@ -0,0 +1,141 @@
const BASE_URL = 'http://localhost:3010'
async function testPrayerAPI() {
console.log('🧪 Testing Prayer API Endpoints...\n')
// Test 1: Get all prayers
console.log('📋 Test 1: Fetching all prayers...')
try {
const response = await fetch(`${BASE_URL}/api/prayers?limit=10`)
const data = await response.json()
console.log(`✅ Success: Retrieved ${data.prayers?.length || 0} prayers`)
console.log(` First prayer: ${data.prayers?.[0]?.title || 'N/A'}\n`)
} catch (error) {
console.log(`❌ Error fetching prayers: ${error}\n`)
}
// Test 2: Get prayers by category
console.log('📋 Test 2: Fetching prayers by category (health)...')
try {
const response = await fetch(`${BASE_URL}/api/prayers?category=health&limit=5`)
const data = await response.json()
console.log(`✅ Success: Retrieved ${data.prayers?.length || 0} health prayers\n`)
} catch (error) {
console.log(`❌ Error fetching category prayers: ${error}\n`)
}
// Test 3: Create a new prayer
console.log('📋 Test 3: Creating a new prayer request...')
try {
const newPrayer = {
title: 'Test Prayer Request',
description: 'This is a test prayer request created by the testing script.',
category: 'personal',
isAnonymous: false
}
const response = await fetch(`${BASE_URL}/api/prayers`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(newPrayer)
})
const data = await response.json()
if (response.ok) {
console.log(`✅ Success: Created prayer with ID: ${data.prayer?.id}`)
console.log(` Title: ${data.prayer?.title}\n`)
return data.prayer?.id // Return ID for next test
} else {
console.log(`❌ Error: ${data.error}\n`)
}
} catch (error) {
console.log(`❌ Error creating prayer: ${error}\n`)
}
// Test 4: Update prayer count (pray for a prayer)
console.log('📋 Test 4: Testing prayer count update...')
try {
// Get first prayer ID
const getResponse = await fetch(`${BASE_URL}/api/prayers?limit=1`)
const getData = await getResponse.json()
const prayerId = getData.prayers?.[0]?.id
if (prayerId) {
const response = await fetch(`${BASE_URL}/api/prayers/${prayerId}/pray`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})
const data = await response.json()
if (response.ok) {
console.log(`✅ Success: Updated prayer count`)
console.log(` New count: ${data.prayerCount}\n`)
} else {
console.log(`❌ Error: ${data.error}\n`)
}
} else {
console.log('❌ No prayer found to test with\n')
}
} catch (error) {
console.log(`❌ Error updating prayer count: ${error}\n`)
}
// Test 5: Generate AI prayer
console.log('📋 Test 5: Testing AI prayer generation...')
try {
const aiRequest = {
prompt: 'I need strength to overcome my anxiety about the future',
category: 'personal',
locale: 'en'
}
const response = await fetch(`${BASE_URL}/api/prayers/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(aiRequest)
})
const data = await response.json()
if (response.ok) {
console.log(`✅ Success: Generated AI prayer`)
console.log(` Title: ${data.title}`)
console.log(` Prayer preview: ${data.prayer?.substring(0, 100)}...\n`)
} else {
console.log(`❌ Error: ${data.error}\n`)
}
} catch (error) {
console.log(`❌ Error generating AI prayer: ${error}\n`)
}
// Test 6: Generate Romanian AI prayer
console.log('📋 Test 6: Testing Romanian AI prayer generation...')
try {
const aiRequest = {
prompt: 'Am nevoie de înțelepciune pentru o decizie importantă',
category: 'personal',
locale: 'ro'
}
const response = await fetch(`${BASE_URL}/api/prayers/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(aiRequest)
})
const data = await response.json()
if (response.ok) {
console.log(`✅ Success: Generated Romanian AI prayer`)
console.log(` Title: ${data.title}`)
console.log(` Prayer preview: ${data.prayer?.substring(0, 100)}...\n`)
} else {
console.log(`❌ Error: ${data.error}\n`)
}
} catch (error) {
console.log(`❌ Error generating Romanian AI prayer: ${error}\n`)
}
console.log('✨ Prayer API testing completed!')
}
// Run tests
testPrayerAPI().catch(console.error)