feat: add backend API endpoints for highlights and cross-references
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
42
app/api/highlights/all/route.ts
Normal file
42
app/api/highlights/all/route.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { getAuth } from '@clerk/nextjs/server'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { userId } = await getAuth(request)
|
||||
if (!userId) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const highlights = await prisma.userHighlight.findMany({
|
||||
where: { userId },
|
||||
select: {
|
||||
id: true,
|
||||
verseId: true,
|
||||
color: true,
|
||||
createdAt: true,
|
||||
updatedAt: true
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
highlights: highlights.map(h => ({
|
||||
id: h.id,
|
||||
verseId: h.verseId,
|
||||
color: h.color,
|
||||
createdAt: h.createdAt.getTime(),
|
||||
updatedAt: h.updatedAt.getTime()
|
||||
})),
|
||||
serverTime: Date.now()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching highlights:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch highlights' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user