guest book added

This commit is contained in:
2025-06-26 12:37:34 -04:00
parent 6aceafeb67
commit 29c91fee7f
17 changed files with 622 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ export default async function EventsPage() {
<div>
{allEvents.length == 0 ? (
<>
You don't have any events yet. <Link href={'/events/create'} className='underline'>Create One!</Link>
You don&apos;t have any events yet. <Link href={'/events/create'} className='underline'>Create One!</Link>
</>
) : (
<table className='table-auto w-full'>

View File

@@ -0,0 +1,13 @@
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
import { queries } from '@/lib/queries'
import { getServerSession } from 'next-auth'
import GuestBookPageClient from '@/components/GuestBookPageClient'
export default async function GuestBookPage() {
const session = await getServerSession(authOptions)
if (!session?.user) return <p className='text-center mt-10'>Unauthorized</p>
const entries = await queries.fetchGuestBookEntries()
return <GuestBookPageClient entries={entries} />
}

View File

@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from 'next/server'
import { mutations } from '@/lib/mutations'
import { getServerSession } from 'next-auth'
import { authOptions } from '../../auth/[...nextauth]/route'
export async function PATCH(req: NextRequest, { params }: { params: { id: string } }) {
const session = await getServerSession(authOptions)
if (!session?.user || !['COUPLE', 'PLANNER'].includes(session.user.role)) {
return new NextResponse('Unauthorized', { status: 403 })
}
try {
const data = await req.json()
const updated = await mutations.updateGuestBookEntry(params.id, data)
return NextResponse.json(updated)
} catch (err) {
console.error('[EDIT GUESTBOOK ENTRY]', err)
return new NextResponse('Failed to update guestbook entry', { status: 500 })
}
}

View File

@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from 'next/server'
import { mutations } from '@/lib/mutations'
import { getServerSession } from 'next-auth'
import { authOptions } from '../../auth/[...nextauth]/route'
export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions)
if (!session?.user || !['COUPLE', 'PLANNER'].includes(session.user.role)) {
return new NextResponse('Unauthorized', { status: 403 })
}
try {
const data = await req.json()
const entry = await mutations.createGuestBookEntry(data)
return NextResponse.json(entry)
} catch (err) {
console.error('[ADD GUESTBOOK ENTRY]', err)
return new NextResponse('Failed to create guestbook entry', { status: 500 })
}
}