feat: 질문지 제출 기능 + 관리자 응답 관리 + iframe 미리보기 수정

- 질문지 HTML에 제출/임시저장 JavaScript 추가 (localStorage 임시저장, API 제출)
- questionnaire_responses 테이블 마이그레이션 (005)
- /api/questionnaire/submit POST 엔드포인트
- 관리자 질문지 응답 목록/상세/상태변경 페이지 및 API
- 관리자 문서 미리보기를 fetch+srcdoc 방식으로 변경 (X-Frame-Options 우회)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-03 00:44:27 +09:00
parent 14996a320b
commit e27d13b6ec
9 changed files with 720 additions and 22 deletions

View File

@@ -0,0 +1,69 @@
import { NextResponse } from 'next/server';
import { createAdminClient } from '@/lib/supabase/admin';
import { verifyAdminTokenNode } from '@/lib/admin-auth';
import { cookies } from 'next/headers';
export const runtime = 'nodejs';
async function checkAuth() {
const cookieStore = await cookies();
const token = cookieStore.get('admin_token')?.value;
return token && verifyAdminTokenNode(token);
}
// 질문지 응답 상세 조회
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
if (!(await checkAuth())) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const { id } = await params;
const admin = createAdminClient();
const { data, error } = await admin
.from('questionnaire_responses')
.select('*')
.eq('id', id)
.single();
if (error) {
console.error('[Admin Questionnaire] DB error:', error);
return NextResponse.json({ error: '조회 실패' }, { status: 500 });
}
return NextResponse.json({ data });
}
// 상태/메모 업데이트
export async function PATCH(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
if (!(await checkAuth())) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const { id } = await params;
const body = await request.json();
const { status, admin_notes } = body;
const updates: Record<string, unknown> = {};
if (status) updates.status = status;
if (admin_notes !== undefined) updates.admin_notes = admin_notes;
if (status === 'reviewed') updates.reviewed_at = new Date().toISOString();
const admin = createAdminClient();
const { error } = await admin
.from('questionnaire_responses')
.update(updates)
.eq('id', id);
if (error) {
console.error('[Admin Questionnaire] Update error:', error);
return NextResponse.json({ error: '업데이트 실패' }, { status: 500 });
}
return NextResponse.json({ success: true });
}

View File

@@ -0,0 +1,32 @@
import { NextResponse } from 'next/server';
import { createAdminClient } from '@/lib/supabase/admin';
import { verifyAdminTokenNode } from '@/lib/admin-auth';
import { cookies } from 'next/headers';
export const runtime = 'nodejs';
async function checkAuth() {
const cookieStore = await cookies();
const token = cookieStore.get('admin_token')?.value;
return token && verifyAdminTokenNode(token);
}
// 질문지 응답 목록 조회
export async function GET() {
if (!(await checkAuth())) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const admin = createAdminClient();
const { data, error } = await admin
.from('questionnaire_responses')
.select('*')
.order('created_at', { ascending: false });
if (error) {
console.error('[Admin Questionnaire] DB error:', error);
return NextResponse.json({ error: '데이터 조회 실패' }, { status: 500 });
}
return NextResponse.json({ data });
}