114 lines
3.0 KiB
TypeScript
114 lines
3.0 KiB
TypeScript
|
|
// 배치관리 전용 API 클라이언트 (기존 소스와 완전 분리)
|
||
|
|
// 작성일: 2024-12-24
|
||
|
|
|
||
|
|
import { apiClient } from "./client";
|
||
|
|
|
||
|
|
// 배치관리 전용 타입 정의
|
||
|
|
export interface BatchConnectionInfo {
|
||
|
|
type: 'internal' | 'external';
|
||
|
|
id?: number;
|
||
|
|
name: string;
|
||
|
|
db_type?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface BatchColumnInfo {
|
||
|
|
column_name: string;
|
||
|
|
data_type: string;
|
||
|
|
is_nullable?: string;
|
||
|
|
column_default?: string | null;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface BatchTableInfo {
|
||
|
|
table_name: string;
|
||
|
|
columns: BatchColumnInfo[];
|
||
|
|
description?: string | null;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface BatchApiResponse<T = unknown> {
|
||
|
|
success: boolean;
|
||
|
|
data?: T;
|
||
|
|
message?: string;
|
||
|
|
error?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const BatchManagementAPI = {
|
||
|
|
BASE_PATH: "/api/batch-management",
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 사용 가능한 커넥션 목록 조회
|
||
|
|
*/
|
||
|
|
static async getAvailableConnections(): Promise<BatchConnectionInfo[]> {
|
||
|
|
try {
|
||
|
|
const response = await apiClient.get<BatchApiResponse<BatchConnectionInfo[]>>(
|
||
|
|
`${this.BASE_PATH}/connections`
|
||
|
|
);
|
||
|
|
|
||
|
|
if (!response.data.success) {
|
||
|
|
throw new Error(response.data.message || "커넥션 목록 조회에 실패했습니다.");
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.data.data || [];
|
||
|
|
} catch (error) {
|
||
|
|
console.error("커넥션 목록 조회 오류:", error);
|
||
|
|
throw error;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 특정 커넥션의 테이블 목록 조회
|
||
|
|
*/
|
||
|
|
static async getTablesFromConnection(
|
||
|
|
connectionType: 'internal' | 'external',
|
||
|
|
connectionId?: number
|
||
|
|
): Promise<string[]> {
|
||
|
|
try {
|
||
|
|
let url = `${this.BASE_PATH}/connections/${connectionType}`;
|
||
|
|
if (connectionType === 'external' && connectionId) {
|
||
|
|
url += `/${connectionId}`;
|
||
|
|
}
|
||
|
|
url += '/tables';
|
||
|
|
|
||
|
|
const response = await apiClient.get<BatchApiResponse<BatchTableInfo[]>>(url);
|
||
|
|
|
||
|
|
if (!response.data.success) {
|
||
|
|
throw new Error(response.data.message || "테이블 목록 조회에 실패했습니다.");
|
||
|
|
}
|
||
|
|
|
||
|
|
// BatchTableInfo[]에서 table_name만 추출하여 string[]로 변환
|
||
|
|
const tables = response.data.data || [];
|
||
|
|
return tables.map(table => table.table_name);
|
||
|
|
} catch (error) {
|
||
|
|
console.error("테이블 목록 조회 오류:", error);
|
||
|
|
throw error;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 특정 테이블의 컬럼 정보 조회
|
||
|
|
*/
|
||
|
|
static async getTableColumns(
|
||
|
|
connectionType: 'internal' | 'external',
|
||
|
|
tableName: string,
|
||
|
|
connectionId?: number
|
||
|
|
): Promise<BatchColumnInfo[]> {
|
||
|
|
try {
|
||
|
|
let url = `${this.BASE_PATH}/connections/${connectionType}`;
|
||
|
|
if (connectionType === 'external' && connectionId) {
|
||
|
|
url += `/${connectionId}`;
|
||
|
|
}
|
||
|
|
url += `/tables/${tableName}/columns`;
|
||
|
|
|
||
|
|
const response = await apiClient.get<BatchApiResponse<BatchColumnInfo[]>>(url);
|
||
|
|
|
||
|
|
if (!response.data.success) {
|
||
|
|
throw new Error(response.data.message || "컬럼 정보 조회에 실패했습니다.");
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.data.data || [];
|
||
|
|
} catch (error) {
|
||
|
|
console.error("컬럼 정보 조회 오류:", error);
|
||
|
|
throw error;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|