feat: Digital Twin Editor 테이블 매핑 UI 및 백엔드 API 구현
This commit is contained in:
215
frontend/lib/api/digitalTwin.ts
Normal file
215
frontend/lib/api/digitalTwin.ts
Normal file
@@ -0,0 +1,215 @@
|
||||
import { apiClient } from "./client";
|
||||
import type {
|
||||
DigitalTwinLayout,
|
||||
DigitalTwinLayoutDetail,
|
||||
CreateLayoutRequest,
|
||||
UpdateLayoutRequest,
|
||||
Warehouse,
|
||||
Area,
|
||||
Location,
|
||||
MaterialData,
|
||||
MaterialCount,
|
||||
} from "@/types/digitalTwin";
|
||||
|
||||
// API 응답 타입
|
||||
interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// ========== 레이아웃 관리 API ==========
|
||||
|
||||
// 레이아웃 목록 조회
|
||||
export const getLayouts = async (params?: {
|
||||
externalDbConnectionId?: number;
|
||||
warehouseKey?: string;
|
||||
}): Promise<ApiResponse<DigitalTwinLayout[]>> => {
|
||||
try {
|
||||
const response = await apiClient.get("/digital-twin/layouts", { params });
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 레이아웃 상세 조회
|
||||
export const getLayoutById = async (id: number): Promise<ApiResponse<DigitalTwinLayoutDetail>> => {
|
||||
try {
|
||||
const response = await apiClient.get(`/digital-twin/layouts/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 레이아웃 생성
|
||||
export const createLayout = async (data: CreateLayoutRequest): Promise<ApiResponse<DigitalTwinLayout>> => {
|
||||
try {
|
||||
const response = await apiClient.post("/digital-twin/layouts", data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 레이아웃 수정
|
||||
export const updateLayout = async (id: number, data: UpdateLayoutRequest): Promise<ApiResponse<DigitalTwinLayout>> => {
|
||||
try {
|
||||
const response = await apiClient.put(`/digital-twin/layouts/${id}`, data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 레이아웃 삭제
|
||||
export const deleteLayout = async (id: number): Promise<ApiResponse<void>> => {
|
||||
try {
|
||||
const response = await apiClient.delete(`/digital-twin/layouts/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// ========== 외부 DB 테이블 조회 API ==========
|
||||
|
||||
export const getTables = async (
|
||||
connectionId: number
|
||||
): Promise<ApiResponse<Array<{ table_name: string }>>> => {
|
||||
try {
|
||||
const response = await apiClient.get(`/digital-twin/data/tables/${connectionId}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const getTablePreview = async (
|
||||
connectionId: number,
|
||||
tableName: string
|
||||
): Promise<ApiResponse<any[]>> => {
|
||||
try {
|
||||
const response = await apiClient.get(`/digital-twin/data/table-preview/${connectionId}/${tableName}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// ========== 외부 DB 데이터 조회 API ==========
|
||||
|
||||
// 창고 목록 조회
|
||||
export const getWarehouses = async (externalDbConnectionId: number, tableName: string): Promise<ApiResponse<Warehouse[]>> => {
|
||||
try {
|
||||
const response = await apiClient.get("/digital-twin/data/warehouses", {
|
||||
params: { externalDbConnectionId, tableName },
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Area 목록 조회
|
||||
export const getAreas = async (externalDbConnectionId: number, tableName: string, warehouseKey: string): Promise<ApiResponse<Area[]>> => {
|
||||
try {
|
||||
const response = await apiClient.get("/digital-twin/data/areas", {
|
||||
params: { externalDbConnectionId, tableName, warehouseKey },
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Location 목록 조회
|
||||
export const getLocations = async (
|
||||
externalDbConnectionId: number,
|
||||
tableName: string,
|
||||
areaKey: string,
|
||||
): Promise<ApiResponse<Location[]>> => {
|
||||
try {
|
||||
const response = await apiClient.get("/digital-twin/data/locations", {
|
||||
params: { externalDbConnectionId, tableName, areaKey },
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 자재 목록 조회 (특정 Location)
|
||||
export const getMaterials = async (
|
||||
externalDbConnectionId: number,
|
||||
tableName: string,
|
||||
locaKey: string,
|
||||
): Promise<ApiResponse<MaterialData[]>> => {
|
||||
try {
|
||||
const response = await apiClient.get("/digital-twin/data/materials", {
|
||||
params: { externalDbConnectionId, tableName, locaKey },
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 자재 개수 조회 (여러 Location)
|
||||
export const getMaterialCounts = async (
|
||||
externalDbConnectionId: number,
|
||||
tableName: string,
|
||||
locaKeys: string[],
|
||||
): Promise<ApiResponse<MaterialCount[]>> => {
|
||||
try {
|
||||
const response = await apiClient.get("/digital-twin/data/material-counts", {
|
||||
params: {
|
||||
externalDbConnectionId,
|
||||
tableName,
|
||||
locaKeys: locaKeys.join(","),
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user