86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import express from "express";
|
|
import { authenticateToken } from "../middleware/authMiddleware";
|
|
|
|
// 레이아웃 관리
|
|
import {
|
|
getLayouts,
|
|
getLayoutById,
|
|
createLayout,
|
|
updateLayout,
|
|
deleteLayout,
|
|
} from "../controllers/digitalTwinLayoutController";
|
|
import {
|
|
listMappingTemplates,
|
|
getMappingTemplateById,
|
|
createMappingTemplate,
|
|
} from "../controllers/digitalTwinTemplateController";
|
|
|
|
// 외부 DB 데이터 조회
|
|
import {
|
|
getHierarchyData,
|
|
getChildrenData,
|
|
getWarehouses,
|
|
getAreas,
|
|
getLocations,
|
|
getMaterials,
|
|
getMaterialCounts,
|
|
} from "../controllers/digitalTwinDataController";
|
|
|
|
const router = express.Router();
|
|
|
|
// 모든 라우트에 인증 미들웨어 적용
|
|
router.use(authenticateToken);
|
|
|
|
// ========== 레이아웃 관리 API ==========
|
|
router.get("/layouts", getLayouts); // 레이아웃 목록
|
|
router.get("/layouts/:id", getLayoutById); // 레이아웃 상세
|
|
router.post("/layouts", createLayout); // 레이아웃 생성
|
|
router.put("/layouts/:id", updateLayout); // 레이아웃 수정
|
|
router.delete("/layouts/:id", deleteLayout); // 레이아웃 삭제
|
|
|
|
// ========== 매핑 템플릿 API ==========
|
|
router.get("/mapping-templates", listMappingTemplates);
|
|
router.get("/mapping-templates/:id", getMappingTemplateById);
|
|
router.post("/mapping-templates", createMappingTemplate);
|
|
|
|
// ========== 외부 DB 데이터 조회 API ==========
|
|
|
|
// 동적 계층 구조 API
|
|
router.post("/data/hierarchy", getHierarchyData); // 전체 계층 데이터 조회
|
|
router.post("/data/children", getChildrenData); // 특정 부모의 하위 데이터 조회
|
|
|
|
// 테이블 메타데이터 API
|
|
router.get("/data/tables/:connectionId", async (req, res) => {
|
|
// 테이블 목록 조회
|
|
try {
|
|
const { ExternalDbConnectionService } = await import("../services/externalDbConnectionService");
|
|
const result = await ExternalDbConnectionService.getTablesFromConnection(Number(req.params.connectionId));
|
|
return res.json(result);
|
|
} catch (error: any) {
|
|
return res.status(500).json({ success: false, error: error.message });
|
|
}
|
|
});
|
|
|
|
router.get("/data/table-preview/:connectionId/:tableName", async (req, res) => {
|
|
// 테이블 미리보기 (10개 레코드)
|
|
try {
|
|
const { connectionId, tableName } = req.params;
|
|
const { getExternalDbConnector } = await import("../controllers/digitalTwinDataController");
|
|
const connector = await getExternalDbConnector(Number(connectionId));
|
|
const result = await connector.executeQuery(`SELECT * FROM ${tableName} LIMIT 10`);
|
|
return res.json({ success: true, data: result.rows });
|
|
} catch (error: any) {
|
|
return res.status(500).json({ success: false, error: error.message });
|
|
}
|
|
});
|
|
|
|
// 레거시 API (호환성 유지)
|
|
router.get("/data/warehouses", getWarehouses); // 창고 목록
|
|
router.get("/data/areas", getAreas); // Area 목록
|
|
router.get("/data/locations", getLocations); // Location 목록
|
|
router.get("/data/materials", getMaterials); // 자재 목록 (특정 Location)
|
|
router.post("/data/material-counts", getMaterialCounts); // 자재 개수 (여러 Location) - POST로 변경
|
|
|
|
export default router;
|
|
|