타입 관리 개선 및 화면 비율조정 중간커밋
This commit is contained in:
223
frontend/lib/api/tableManagement.ts
Normal file
223
frontend/lib/api/tableManagement.ts
Normal file
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* 테이블 관리 API
|
||||
* 테이블 컬럼 정보 조회 및 관리 기능
|
||||
*/
|
||||
|
||||
import { apiClient, ApiResponse } from "./client";
|
||||
|
||||
// 컬럼 정보 타입 (백엔드와 일치)
|
||||
export interface ColumnTypeInfo {
|
||||
tableName?: string;
|
||||
columnName: string;
|
||||
displayName: string;
|
||||
dataType: string;
|
||||
dbType: string;
|
||||
webType: string;
|
||||
inputType?: "direct" | "auto";
|
||||
detailSettings: string;
|
||||
description?: string;
|
||||
isNullable: string;
|
||||
isPrimaryKey: boolean;
|
||||
defaultValue?: string;
|
||||
maxLength?: number;
|
||||
numericPrecision?: number;
|
||||
numericScale?: number;
|
||||
codeCategory?: string;
|
||||
codeValue?: string;
|
||||
referenceTable?: string;
|
||||
referenceColumn?: string;
|
||||
displayColumn?: string;
|
||||
displayOrder?: number;
|
||||
isVisible?: boolean;
|
||||
}
|
||||
|
||||
// 테이블 정보 타입
|
||||
export interface TableInfo {
|
||||
tableName: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
columnCount: number;
|
||||
}
|
||||
|
||||
// 컬럼 설정 타입
|
||||
export interface ColumnSettings {
|
||||
columnName?: string;
|
||||
columnLabel: string;
|
||||
webType: string;
|
||||
detailSettings: string;
|
||||
codeCategory: string;
|
||||
codeValue: string;
|
||||
referenceTable: string;
|
||||
referenceColumn: string;
|
||||
displayColumn?: string;
|
||||
displayOrder?: number;
|
||||
isVisible?: boolean;
|
||||
}
|
||||
|
||||
// API 응답 타입들
|
||||
export interface TableListResponse extends ApiResponse<TableInfo[]> {}
|
||||
export interface ColumnListResponse extends ApiResponse<ColumnTypeInfo[]> {}
|
||||
export interface ColumnSettingsResponse extends ApiResponse<void> {}
|
||||
|
||||
/**
|
||||
* 테이블 관리 API 클래스
|
||||
*/
|
||||
class TableManagementApi {
|
||||
private readonly basePath = "/table-management";
|
||||
|
||||
/**
|
||||
* 테이블 목록 조회
|
||||
*/
|
||||
async getTableList(): Promise<TableListResponse> {
|
||||
try {
|
||||
const response = await apiClient.get(`${this.basePath}/tables`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error("❌ 테이블 목록 조회 실패:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || "테이블 목록을 조회할 수 없습니다.",
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 테이블의 컬럼 목록 조회
|
||||
*/
|
||||
async getColumnList(tableName: string): Promise<ColumnListResponse> {
|
||||
try {
|
||||
const response = await apiClient.get(`${this.basePath}/tables/${tableName}/columns`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error(`❌ 테이블 '${tableName}' 컬럼 목록 조회 실패:`, error);
|
||||
return {
|
||||
success: false,
|
||||
message:
|
||||
error.response?.data?.message || error.message || `테이블 '${tableName}'의 컬럼 정보를 조회할 수 없습니다.`,
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 컬럼 타입 설정 저장
|
||||
*/
|
||||
async updateColumnSettings(
|
||||
tableName: string,
|
||||
columnName: string,
|
||||
settings: ColumnSettings,
|
||||
): Promise<ColumnSettingsResponse> {
|
||||
try {
|
||||
const response = await apiClient.put(`${this.basePath}/tables/${tableName}/columns/${columnName}`, settings);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error(`❌ 컬럼 '${tableName}.${columnName}' 설정 저장 실패:`, error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || "컬럼 설정을 저장할 수 없습니다.",
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 여러 컬럼 설정 일괄 저장
|
||||
*/
|
||||
async updateMultipleColumnSettings(
|
||||
tableName: string,
|
||||
settingsArray: Array<{ columnName: string; settings: ColumnSettings }>,
|
||||
): Promise<ColumnSettingsResponse> {
|
||||
try {
|
||||
const response = await apiClient.put(`${this.basePath}/tables/${tableName}/columns/batch`, {
|
||||
settings: settingsArray,
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error(`❌ 테이블 '${tableName}' 컬럼 설정 일괄 저장 실패:`, error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || "컬럼 설정을 일괄 저장할 수 없습니다.",
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 테이블 스키마 정보 조회 (컬럼 존재 여부 검증용)
|
||||
*/
|
||||
async getTableSchema(tableName: string): Promise<ApiResponse<ColumnTypeInfo[]>> {
|
||||
try {
|
||||
const response = await apiClient.get(`${this.basePath}/tables/${tableName}/schema`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error(`❌ 테이블 '${tableName}' 스키마 조회 실패:`, error);
|
||||
return {
|
||||
success: false,
|
||||
message:
|
||||
error.response?.data?.message || error.message || `테이블 '${tableName}'의 스키마 정보를 조회할 수 없습니다.`,
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 테이블 존재 여부 확인
|
||||
*/
|
||||
async checkTableExists(tableName: string): Promise<ApiResponse<{ exists: boolean }>> {
|
||||
try {
|
||||
const response = await apiClient.get(`${this.basePath}/tables/${tableName}/exists`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error(`❌ 테이블 '${tableName}' 존재 여부 확인 실패:`, error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || "테이블 존재 여부를 확인할 수 없습니다.",
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 컬럼 웹타입 정보 조회 (화면관리 연동용)
|
||||
*/
|
||||
async getColumnWebTypes(tableName: string): Promise<ApiResponse<ColumnTypeInfo[]>> {
|
||||
try {
|
||||
const response = await apiClient.get(`${this.basePath}/tables/${tableName}/web-types`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error(`❌ 테이블 '${tableName}' 웹타입 정보 조회 실패:`, error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || "웹타입 정보를 조회할 수 없습니다.",
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터베이스 연결 상태 확인
|
||||
*/
|
||||
async checkDatabaseConnection(): Promise<ApiResponse<{ connected: boolean; message: string }>> {
|
||||
try {
|
||||
const response = await apiClient.get(`${this.basePath}/health`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error("❌ 데이터베이스 연결 상태 확인 실패:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || "데이터베이스 연결 상태를 확인할 수 없습니다.",
|
||||
errorCode: error.response?.data?.errorCode,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 싱글톤 인스턴스 생성
|
||||
export const tableManagementApi = new TableManagementApi();
|
||||
|
||||
// 편의 함수들
|
||||
export const getTableColumns = (tableName: string) => tableManagementApi.getColumnList(tableName);
|
||||
export const updateColumnType = (tableName: string, columnName: string, settings: ColumnSettings) =>
|
||||
tableManagementApi.updateColumnSettings(tableName, columnName, settings);
|
||||
export const checkTableExists = (tableName: string) => tableManagementApi.checkTableExists(tableName);
|
||||
Reference in New Issue
Block a user