2025-08-25 14:08:08 +09:00
|
|
|
import { Request, Response } from "express";
|
2025-09-01 15:22:47 +09:00
|
|
|
import { Client } from "pg";
|
2025-08-25 14:08:08 +09:00
|
|
|
import { logger } from "../utils/logger";
|
|
|
|
|
import { AuthenticatedRequest } from "../types/auth";
|
|
|
|
|
import { ApiResponse } from "../types/common";
|
|
|
|
|
import { TableManagementService } from "../services/tableManagementService";
|
|
|
|
|
import {
|
|
|
|
|
TableInfo,
|
|
|
|
|
ColumnTypeInfo,
|
|
|
|
|
ColumnSettings,
|
|
|
|
|
TableListResponse,
|
|
|
|
|
ColumnListResponse,
|
|
|
|
|
ColumnSettingsResponse,
|
|
|
|
|
} from "../types/tableManagement";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테이블 목록 조회
|
|
|
|
|
*/
|
|
|
|
|
export async function getTableList(
|
|
|
|
|
req: AuthenticatedRequest,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
logger.info("=== 테이블 목록 조회 시작 ===");
|
|
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const tableManagementService = new TableManagementService();
|
|
|
|
|
const tableList = await tableManagementService.getTableList();
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
logger.info(`테이블 목록 조회 결과: ${tableList.length}개`);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const response: ApiResponse<TableInfo[]> = {
|
|
|
|
|
success: true,
|
|
|
|
|
message: "테이블 목록을 성공적으로 조회했습니다.",
|
|
|
|
|
data: tableList,
|
|
|
|
|
};
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
res.status(200).json(response);
|
2025-08-25 14:08:08 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("테이블 목록 조회 중 오류 발생:", error);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블 목록 조회 중 오류가 발생했습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "TABLE_LIST_ERROR",
|
|
|
|
|
details: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(500).json(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테이블 컬럼 정보 조회
|
|
|
|
|
*/
|
|
|
|
|
export async function getColumnList(
|
|
|
|
|
req: AuthenticatedRequest,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
const { tableName } = req.params;
|
|
|
|
|
logger.info(`=== 컬럼 정보 조회 시작: ${tableName} ===`);
|
|
|
|
|
|
|
|
|
|
if (!tableName) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블명이 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_TABLE_NAME",
|
|
|
|
|
details: "테이블명 파라미터가 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const tableManagementService = new TableManagementService();
|
|
|
|
|
const columnList = await tableManagementService.getColumnList(tableName);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
logger.info(`컬럼 정보 조회 결과: ${tableName}, ${columnList.length}개`);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const response: ApiResponse<ColumnTypeInfo[]> = {
|
|
|
|
|
success: true,
|
|
|
|
|
message: "컬럼 목록을 성공적으로 조회했습니다.",
|
|
|
|
|
data: columnList,
|
|
|
|
|
};
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
res.status(200).json(response);
|
2025-08-25 14:08:08 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("컬럼 정보 조회 중 오류 발생:", error);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 목록 조회 중 오류가 발생했습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "COLUMN_LIST_ERROR",
|
|
|
|
|
details: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(500).json(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 개별 컬럼 설정 업데이트
|
|
|
|
|
*/
|
|
|
|
|
export async function updateColumnSettings(
|
|
|
|
|
req: AuthenticatedRequest,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
const { tableName, columnName } = req.params;
|
|
|
|
|
const settings: ColumnSettings = req.body;
|
|
|
|
|
|
|
|
|
|
logger.info(`=== 컬럼 설정 업데이트 시작: ${tableName}.${columnName} ===`);
|
|
|
|
|
|
|
|
|
|
if (!tableName || !columnName) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블명과 컬럼명이 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_PARAMETERS",
|
|
|
|
|
details: "테이블명 또는 컬럼명 파라미터가 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!settings) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 설정 정보가 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_SETTINGS",
|
|
|
|
|
details: "요청 본문에 컬럼 설정 정보가 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const tableManagementService = new TableManagementService();
|
|
|
|
|
await tableManagementService.updateColumnSettings(
|
|
|
|
|
tableName,
|
|
|
|
|
columnName,
|
|
|
|
|
settings
|
|
|
|
|
);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
logger.info(`컬럼 설정 업데이트 완료: ${tableName}.${columnName}`);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: true,
|
|
|
|
|
message: "컬럼 설정을 성공적으로 저장했습니다.",
|
|
|
|
|
};
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
res.status(200).json(response);
|
2025-08-25 14:08:08 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("컬럼 설정 업데이트 중 오류 발생:", error);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 설정 저장 중 오류가 발생했습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "COLUMN_SETTINGS_UPDATE_ERROR",
|
|
|
|
|
details: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(500).json(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 전체 컬럼 설정 일괄 업데이트
|
|
|
|
|
*/
|
|
|
|
|
export async function updateAllColumnSettings(
|
|
|
|
|
req: AuthenticatedRequest,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
const { tableName } = req.params;
|
|
|
|
|
const columnSettings: ColumnSettings[] = req.body;
|
|
|
|
|
|
|
|
|
|
logger.info(`=== 전체 컬럼 설정 일괄 업데이트 시작: ${tableName} ===`);
|
|
|
|
|
|
|
|
|
|
if (!tableName) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블명이 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_TABLE_NAME",
|
|
|
|
|
details: "테이블명 파라미터가 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Array.isArray(columnSettings) || columnSettings.length === 0) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 설정 목록이 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_COLUMN_SETTINGS",
|
|
|
|
|
details: "요청 본문에 컬럼 설정 목록이 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const tableManagementService = new TableManagementService();
|
|
|
|
|
await tableManagementService.updateAllColumnSettings(
|
|
|
|
|
tableName,
|
|
|
|
|
columnSettings
|
|
|
|
|
);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
logger.info(
|
|
|
|
|
`전체 컬럼 설정 일괄 업데이트 완료: ${tableName}, ${columnSettings.length}개`
|
|
|
|
|
);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: true,
|
|
|
|
|
message: "모든 컬럼 설정을 성공적으로 저장했습니다.",
|
|
|
|
|
};
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
res.status(200).json(response);
|
2025-08-25 14:08:08 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("전체 컬럼 설정 일괄 업데이트 중 오류 발생:", error);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 설정 저장 중 오류가 발생했습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "ALL_COLUMN_SETTINGS_UPDATE_ERROR",
|
|
|
|
|
details: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(500).json(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테이블 라벨 정보 조회
|
|
|
|
|
*/
|
|
|
|
|
export async function getTableLabels(
|
|
|
|
|
req: AuthenticatedRequest,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
const { tableName } = req.params;
|
|
|
|
|
logger.info(`=== 테이블 라벨 정보 조회 시작: ${tableName} ===`);
|
|
|
|
|
|
|
|
|
|
if (!tableName) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블명이 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_TABLE_NAME",
|
|
|
|
|
details: "테이블명 파라미터가 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const tableManagementService = new TableManagementService();
|
|
|
|
|
const tableLabels = await tableManagementService.getTableLabels(tableName);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
if (!tableLabels) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블 라벨 정보를 찾을 수 없습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "TABLE_LABELS_NOT_FOUND",
|
|
|
|
|
details: `테이블 ${tableName}의 라벨 정보가 존재하지 않습니다.`,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(404).json(response);
|
|
|
|
|
return;
|
2025-08-25 14:08:08 +09:00
|
|
|
}
|
2025-09-01 11:00:38 +09:00
|
|
|
|
|
|
|
|
logger.info(`테이블 라벨 정보 조회 완료: ${tableName}`);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<any> = {
|
|
|
|
|
success: true,
|
|
|
|
|
message: "테이블 라벨 정보를 성공적으로 조회했습니다.",
|
|
|
|
|
data: tableLabels,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(200).json(response);
|
2025-08-25 14:08:08 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("테이블 라벨 정보 조회 중 오류 발생:", error);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블 라벨 정보 조회 중 오류가 발생했습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "TABLE_LABELS_ERROR",
|
|
|
|
|
details: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(500).json(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 컬럼 라벨 정보 조회
|
|
|
|
|
*/
|
|
|
|
|
export async function getColumnLabels(
|
|
|
|
|
req: AuthenticatedRequest,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
const { tableName, columnName } = req.params;
|
|
|
|
|
logger.info(`=== 컬럼 라벨 정보 조회 시작: ${tableName}.${columnName} ===`);
|
|
|
|
|
|
|
|
|
|
if (!tableName || !columnName) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블명과 컬럼명이 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_PARAMETERS",
|
|
|
|
|
details: "테이블명 또는 컬럼명 파라미터가 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
const tableManagementService = new TableManagementService();
|
|
|
|
|
const columnLabels = await tableManagementService.getColumnLabels(
|
|
|
|
|
tableName,
|
|
|
|
|
columnName
|
|
|
|
|
);
|
2025-08-25 14:08:08 +09:00
|
|
|
|
2025-09-01 11:00:38 +09:00
|
|
|
if (!columnLabels) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 라벨 정보를 찾을 수 없습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "COLUMN_LABELS_NOT_FOUND",
|
|
|
|
|
details: `컬럼 ${tableName}.${columnName}의 라벨 정보가 존재하지 않습니다.`,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(404).json(response);
|
|
|
|
|
return;
|
2025-08-25 14:08:08 +09:00
|
|
|
}
|
2025-09-01 11:00:38 +09:00
|
|
|
|
|
|
|
|
logger.info(`컬럼 라벨 정보 조회 완료: ${tableName}.${columnName}`);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<any> = {
|
|
|
|
|
success: true,
|
|
|
|
|
message: "컬럼 라벨 정보를 성공적으로 조회했습니다.",
|
|
|
|
|
data: columnLabels,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(200).json(response);
|
2025-08-25 14:08:08 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("컬럼 라벨 정보 조회 중 오류 발생:", error);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 라벨 정보 조회 중 오류가 발생했습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "COLUMN_LABELS_ERROR",
|
|
|
|
|
details: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(500).json(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-01 11:48:12 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 컬럼 웹 타입 설정
|
|
|
|
|
*/
|
|
|
|
|
export async function updateColumnWebType(
|
|
|
|
|
req: AuthenticatedRequest,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
const { tableName, columnName } = req.params;
|
|
|
|
|
const { webType, detailSettings } = req.body;
|
|
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
|
`=== 컬럼 웹 타입 설정 시작: ${tableName}.${columnName} = ${webType} ===`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!tableName || !columnName || !webType) {
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "테이블명, 컬럼명, 웹 타입이 모두 필요합니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "MISSING_PARAMETERS",
|
|
|
|
|
details: "필수 파라미터가 누락되었습니다.",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
res.status(400).json(response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 15:22:47 +09:00
|
|
|
const tableManagementService = new TableManagementService();
|
|
|
|
|
await tableManagementService.updateColumnWebType(
|
|
|
|
|
tableName,
|
|
|
|
|
columnName,
|
|
|
|
|
webType,
|
|
|
|
|
detailSettings
|
|
|
|
|
);
|
2025-09-01 11:48:12 +09:00
|
|
|
|
2025-09-01 15:22:47 +09:00
|
|
|
logger.info(
|
|
|
|
|
`컬럼 웹 타입 설정 완료: ${tableName}.${columnName} = ${webType}`
|
|
|
|
|
);
|
2025-09-01 11:48:12 +09:00
|
|
|
|
2025-09-01 15:22:47 +09:00
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: true,
|
|
|
|
|
message: "컬럼 웹 타입이 성공적으로 설정되었습니다.",
|
|
|
|
|
data: null,
|
|
|
|
|
};
|
2025-09-01 11:48:12 +09:00
|
|
|
|
2025-09-01 15:22:47 +09:00
|
|
|
res.status(200).json(response);
|
2025-09-01 11:48:12 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("컬럼 웹 타입 설정 중 오류 발생:", error);
|
|
|
|
|
|
|
|
|
|
const response: ApiResponse<null> = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "컬럼 웹 타입 설정 중 오류가 발생했습니다.",
|
|
|
|
|
error: {
|
|
|
|
|
code: "WEB_TYPE_UPDATE_ERROR",
|
|
|
|
|
details: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
res.status(500).json(response);
|
|
|
|
|
}
|
|
|
|
|
}
|