리스트 위젯 REST API 기능 개선

This commit is contained in:
dohyeons
2025-12-11 10:48:48 +09:00
parent e84764dc2b
commit bccb8a6330
5 changed files with 211 additions and 25 deletions

View File

@@ -316,12 +316,14 @@ export function ListTestWidget({ element }: ListTestWidgetProps) {
// 다중 데이터 소스 로딩
const loadMultipleDataSources = useCallback(async () => {
console.log("[ListTestWidget] dataSources:", dataSources);
if (!dataSources || dataSources.length === 0) {
// console.log("⚠️ 데이터 소스가 없습니다.");
console.log("[ListTestWidget] 데이터 소스가 없습니다.");
return;
}
// console.log(`🔄 ${dataSources.length}개의 데이터 소스 로딩 시작...`);
console.log(`[ListTestWidget] ${dataSources.length}개의 데이터 소스 로딩 시작...`, dataSources[0]);
setIsLoading(true);
setError(null);
@@ -412,18 +414,52 @@ export function ListTestWidget({ element }: ListTestWidgetProps) {
});
}
// 요청 메서드 (기본값: GET)
const requestMethod = source.method || "GET";
// 요청 body (POST, PUT, PATCH인 경우)
let requestBody = undefined;
if (["POST", "PUT", "PATCH"].includes(requestMethod) && source.body) {
try {
// body가 문자열이면 JSON 파싱 시도
requestBody = typeof source.body === "string" ? JSON.parse(source.body) : source.body;
} catch {
// 파싱 실패하면 문자열 그대로 사용
requestBody = source.body;
}
}
// headers를 KeyValuePair[] 에서 객체로 변환
const headersObj: Record<string, string> = {};
if (source.headers && Array.isArray(source.headers)) {
source.headers.forEach((h: any) => {
if (h.key && h.value) {
headersObj[h.key] = h.value;
}
});
} else if (source.headers && typeof source.headers === "object") {
// 이미 객체인 경우 그대로 사용
Object.assign(headersObj, source.headers);
}
const requestPayload = {
url: source.endpoint,
method: requestMethod,
headers: headersObj,
queryParams: Object.fromEntries(params),
body: requestBody,
externalConnectionId: source.externalConnectionId,
};
console.log("[ListTestWidget] API 요청:", requestPayload);
const response = await fetch(getApiUrl("/api/dashboards/fetch-external-api"), {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({
url: source.endpoint,
method: "GET",
headers: source.headers || {},
queryParams: Object.fromEntries(params),
}),
body: JSON.stringify(requestPayload),
});
if (!response.ok) {