From 9e280704988fdeffa05c1d8cbb731722f666c6af Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 28 May 2025 00:17:56 +0000 Subject: (대표님) 앱 라우터 api 파트 커밋 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/oracle/[tableName]/route.ts | 42 ++++++++++++++++++++++ app/api/oracle/columns/[tableName]/route.ts | 55 +++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 app/api/oracle/[tableName]/route.ts create mode 100644 app/api/oracle/columns/[tableName]/route.ts (limited to 'app/api/oracle') diff --git a/app/api/oracle/[tableName]/route.ts b/app/api/oracle/[tableName]/route.ts new file mode 100644 index 00000000..0898421d --- /dev/null +++ b/app/api/oracle/[tableName]/route.ts @@ -0,0 +1,42 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { getTableData } from '@/lib/oracle/db'; + +interface Params { + tableName: string; +} + +interface ApiError { + message: string; + error?: string; +} + +/** + * GET 핸들러 - 테이블 데이터 가져오기 + */ +export async function GET( + request: NextRequest, + { params }: { params: Params } +): Promise> { + const { tableName } = params; + + if (!tableName) { + return NextResponse.json( + { message: '테이블 이름이 필요합니다.' }, + { status: 400 } + ); + } + + try { + const data = await getTableData(tableName); + return NextResponse.json({ data }, { status: 200 }); + } catch (error: any) { + console.error('API 에러:', error); + return NextResponse.json( + { + message: '서버 에러가 발생했습니다.', + error: error.message + }, + { status: 500 } + ); + } +} \ No newline at end of file diff --git a/app/api/oracle/columns/[tableName]/route.ts b/app/api/oracle/columns/[tableName]/route.ts new file mode 100644 index 00000000..ba62d7a8 --- /dev/null +++ b/app/api/oracle/columns/[tableName]/route.ts @@ -0,0 +1,55 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { getTableColumns } from '@/lib/oracle/db'; + +interface Params { + tableName: string; +} + +interface ApiError { + message: string; + error?: string; +} + +/** + * GET 핸들러 - 테이블의 특정 컬럼 데이터만 가져오기 + */ +export async function GET( + request: NextRequest, + { params }: { params: Params } +): Promise> { + const { tableName } = params; + + if (!tableName) { + return NextResponse.json( + { message: '테이블 이름이 필요합니다.' }, + { status: 400 } + ); + } + + // 쿼리 파라미터에서 컬럼 목록 가져오기 + const searchParams = request.nextUrl.searchParams; + const columnsParam = searchParams.get('columns'); + + if (!columnsParam) { + return NextResponse.json( + { message: '컬럼 목록이 필요합니다. 예: ?columns=ID,NAME,EMAIL' }, + { status: 400 } + ); + } + + const columns = columnsParam.split(',').map(col => col.trim()); + + try { + const data = await getTableColumns(tableName, columns); + return NextResponse.json({ data }, { status: 200 }); + } catch (error: any) { + console.error('API 에러:', error); + return NextResponse.json( + { + message: '서버 에러가 발생했습니다.', + error: error.message + }, + { status: 500 } + ); + } +} \ No newline at end of file -- cgit v1.2.3