diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-05 01:53:35 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-05 01:53:35 +0000 |
| commit | 610d3bccf1cb640e2a21df28d8d2a954c2bf337e (patch) | |
| tree | e7e6d72fecf14ddcff1b5b52263d14119b7c488c /app/api/sync | |
| parent | 15969dfedffc4e215c81d507164bc2bb383974e5 (diff) | |
(대표님) 변경사항 0604 - OCR 관련 및 drizzle generated sqls
Diffstat (limited to 'app/api/sync')
| -rw-r--r-- | app/api/sync/import/route.ts | 39 | ||||
| -rw-r--r-- | app/api/sync/import/status/route.ts | 41 | ||||
| -rw-r--r-- | app/api/sync/workflow/action/route.ts | 44 | ||||
| -rw-r--r-- | app/api/sync/workflow/status/route.ts | 41 |
4 files changed, 165 insertions, 0 deletions
diff --git a/app/api/sync/import/route.ts b/app/api/sync/import/route.ts new file mode 100644 index 00000000..a6496578 --- /dev/null +++ b/app/api/sync/import/route.ts @@ -0,0 +1,39 @@ +import { NextRequest, NextResponse } from "next/server" +import { importService } from "@/lib/vendor-document-list/import-service" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" + +export async function POST(request: NextRequest) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) + } + + const body = await request.json() + const { contractId, sourceSystem = 'DOLCE' } = body + + if (!contractId) { + return NextResponse.json( + { error: 'Contract ID is required' }, + { status: 400 } + ) + } + + const result = await importService.importFromExternalSystem( + contractId, + sourceSystem + ) + + return NextResponse.json(result) + } catch (error) { + console.error('Import failed:', error) + return NextResponse.json( + { + error: 'Import failed', + message: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ) + } +} diff --git a/app/api/sync/import/status/route.ts b/app/api/sync/import/status/route.ts new file mode 100644 index 00000000..c5b4b0bd --- /dev/null +++ b/app/api/sync/import/status/route.ts @@ -0,0 +1,41 @@ +// app/api/sync/import/status/route.ts +import { NextRequest, NextResponse } from "next/server" +import { importService } from "@/lib/vendor-document-list/import-service" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" + +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 contractId = searchParams.get('contractId') + const sourceSystem = searchParams.get('sourceSystem') || 'DOLCE' + + if (!contractId) { + return NextResponse.json( + { error: 'Contract ID is required' }, + { status: 400 } + ) + } + + const status = await importService.getImportStatus( + Number(contractId), + sourceSystem + ) + + return NextResponse.json(status) + } catch (error) { + console.error('Failed to get import status:', error) + return NextResponse.json( + { + error: 'Failed to get import status', + message: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ) + } +}
\ No newline at end of file diff --git a/app/api/sync/workflow/action/route.ts b/app/api/sync/workflow/action/route.ts new file mode 100644 index 00000000..b6b1a94f --- /dev/null +++ b/app/api/sync/workflow/action/route.ts @@ -0,0 +1,44 @@ +// app/api/sync/workflow/action/route.ts +import { NextRequest, NextResponse } from "next/server" +import { workflowService } from "@/lib/vendor-document-list/workflow-service" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" + +export async function POST(request: NextRequest) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) + } + + const body = await request.json() + const { contractId, targetSystem = 'SWP', action, documents } = body + + if (!contractId || !action) { + return NextResponse.json( + { error: 'Contract ID and action are required' }, + { status: 400 } + ) + } + + const result = await workflowService.executeWorkflowAction( + contractId, + targetSystem, + action, + documents || [], + session.user.id, + session.user.name + ) + + return NextResponse.json(result) + } catch (error) { + console.error('Workflow action failed:', error) + return NextResponse.json( + { + error: 'Workflow action failed', + message: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ) + } +}
\ No newline at end of file diff --git a/app/api/sync/workflow/status/route.ts b/app/api/sync/workflow/status/route.ts new file mode 100644 index 00000000..a4c5d1d0 --- /dev/null +++ b/app/api/sync/workflow/status/route.ts @@ -0,0 +1,41 @@ +// app/api/sync/workflow/status/route.ts +import { NextRequest, NextResponse } from "next/server" +import { workflowService } from "@/lib/vendor-document-list/workflow-service" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" + +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 contractId = searchParams.get('contractId') + const targetSystem = searchParams.get('targetSystem') || 'SWP' + + if (!contractId) { + return NextResponse.json( + { error: 'Contract ID is required' }, + { status: 400 } + ) + } + + const status = await workflowService.getWorkflowStatus( + Number(contractId), + targetSystem + ) + + return NextResponse.json(status) + } catch (error) { + console.error('Failed to get workflow status:', error) + return NextResponse.json( + { + error: 'Failed to get workflow status', + message: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ) + } +}
\ No newline at end of file |
