diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-10-01 10:31:23 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-10-01 10:31:23 +0000 |
| commit | 74843fe598702a9a55f914f2d2d291368a5abb13 (patch) | |
| tree | a88abdaf039f51dd843e0416321f08877b17ea75 /app/api/sync/status/route.ts | |
| parent | 33e8452331c301430191b3506825ebaf3edac93a (diff) | |
(대표님) dolce 수정, spreadjs 수정 등
Diffstat (limited to 'app/api/sync/status/route.ts')
| -rw-r--r-- | app/api/sync/status/route.ts | 105 |
1 files changed, 88 insertions, 17 deletions
diff --git a/app/api/sync/status/route.ts b/app/api/sync/status/route.ts index 05101d2b..71a077ac 100644 --- a/app/api/sync/status/route.ts +++ b/app/api/sync/status/route.ts @@ -1,5 +1,9 @@ +// app/api/sync/status/route.ts + import { syncService } from "@/lib/vendor-document-list/sync-service" import { NextRequest, NextResponse } from "next/server" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" // JSON 직렬화 가능한 형태로 변환하는 헬퍼 함수 function serializeForJSON(obj: any): any { @@ -32,13 +36,20 @@ function serializeForJSON(obj: any): any { export async function GET(request: NextRequest) { try { + + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) + } + const { searchParams } = new URL(request.url) const projectId = searchParams.get('projectId') - const targetSystem = searchParams.get('targetSystem') || 'SHI' + const targetSystem = searchParams.get('targetSystem') || 'DOLCE' // 기본값 DOLCE로 변경 + const realtime = searchParams.get('realtime') === 'true' if (!projectId) { return NextResponse.json( - { error: 'project ID is required' }, + { error: 'Project ID is required' }, { status: 400 } ) } @@ -46,36 +57,96 @@ export async function GET(request: NextRequest) { let status try { - // 실제 데이터베이스에서 조회 시도 + // 실제 데이터베이스에서 조회 status = await syncService.getSyncStatus( parseInt(projectId), targetSystem ) + } catch (error) { - console.log('Database query failed, using mock data:', error) + console.error('Database query failed:', error) - // ✅ 데이터베이스 조회 실패시 임시 목업 데이터 반환 - status = { - projectId: parseInt(projectId), - targetSystem, - totalChanges: 15, - pendingChanges: 3, // 3건 대기 중 (빨간 뱃지 표시용) - syncedChanges: 12, - failedChanges: 0, - lastSyncAt: new Date(Date.now() - 30 * 60 * 1000).toISOString(), // 30분 전 - nextSyncAt: new Date(Date.now() + 10 * 60 * 1000).toISOString(), // 10분 후 - syncEnabled: true + // 개발 환경에서만 목업 데이터 반환 + if (process.env.NODE_ENV === 'development') { + console.log('Using mock data for development') + + status = { + projectId: parseInt(projectId), + vendorId: 1, // 임시 vendorId + targetSystem, + totalChanges: 15, + pendingChanges: 3, + syncedChanges: 12, + failedChanges: 0, + // entityType별 상세 통계 추가 + entityTypeDetails: { + document: { + pending: 1, + synced: 4, + failed: 0, + total: 5 + }, + revision: { + pending: 2, + synced: 6, + failed: 0, + total: 8 + }, + attachment: { + pending: 0, + synced: 2, + failed: 0, + total: 2 + } + }, + lastSyncAt: new Date(Date.now() - 30 * 60 * 1000).toISOString(), + nextSyncAt: new Date(Date.now() + 30 * 60 * 1000).toISOString(), + syncEnabled: true, + hasPendingChanges: true, + hasFailedChanges: false, + syncHealthy: true, + requiresSync:false + } + } else { + // 프로덕션에서는 에러 반환 + return NextResponse.json( + { + error: 'Failed to get sync status', + message: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ) } } // JSON 직렬화 가능한 형태로 변환 const serializedStatus = serializeForJSON(status) - return NextResponse.json(serializedStatus) + // 실시간 모드일 경우 캐시 비활성화 + if (realtime) { + return NextResponse.json(serializedStatus, { + headers: { + 'Cache-Control': 'no-cache, no-store, must-revalidate', + 'Pragma': 'no-cache', + 'Expires': '0' + } + }) + } + + // 일반 모드: 캐시 헤더 설정 (30초) + return NextResponse.json(serializedStatus, { + headers: { + 'Cache-Control': 'public, max-age=30, s-maxage=30, stale-while-revalidate=60' + } + }) + } catch (error) { console.error('Failed to get sync status:', error) return NextResponse.json( - { error: 'Failed to get sync status' }, + { + error: 'Failed to get sync status', + message: error instanceof Error ? error.message : 'Unknown error' + }, { status: 500 } ) } |
