diff --git a/src/app/api/admin/images/route.ts b/src/app/api/admin/images/route.ts index 4bb3727..88e649d 100644 --- a/src/app/api/admin/images/route.ts +++ b/src/app/api/admin/images/route.ts @@ -5,7 +5,7 @@ import { db } from '@/lib/db'; export async function GET() { try { await requireRole('admin'); - const { rows } = await db.query('SELECT id, filename, uploaded_at FROM images ORDER BY uploaded_at DESC'); + const { rows } = await db.query('SELECT id, filename, category, room_id, location_target, uploaded_at FROM images ORDER BY uploaded_at DESC'); return NextResponse.json({ images: rows, count: rows.length }); } catch (error) { if ((error as Error).message === 'Unauthorized') { @@ -20,15 +20,15 @@ export async function POST(request: NextRequest) { try { await requireRole('admin'); const body = await request.json(); - const { filename, data } = body; + const { filename, data, category, room_id, location_target } = body; if (!filename || !data) { return NextResponse.json({ error: 'Missing filename or data' }, { status: 400 }); } const { rows } = await db.query( - 'INSERT INTO images (filename, data) VALUES ($1, $2) RETURNING id, filename, uploaded_at', - [filename, data] + 'INSERT INTO images (filename, data, category, room_id, location_target) VALUES ($1, $2, $3, $4, $5) RETURNING id, filename, category, room_id, location_target, uploaded_at', + [filename, data, category || 'other', room_id || null, location_target || 'gallery'] ); return NextResponse.json({ image: rows[0] }); diff --git a/src/lib/schema.ts b/src/lib/schema.ts index a734aa3..ea95f8a 100644 --- a/src/lib/schema.ts +++ b/src/lib/schema.ts @@ -22,6 +22,7 @@ export async function initSchema() { data TEXT NOT NULL, category VARCHAR(100) DEFAULT 'other', room_id INTEGER REFERENCES rooms(id) ON DELETE SET NULL, + location_target VARCHAR(100) DEFAULT 'gallery', uploaded_at TIMESTAMP DEFAULT NOW() ); `);