api관리 구현(대시보드쪽)
This commit is contained in:
@@ -27,6 +27,36 @@ export interface ExternalDbConnection {
|
||||
updated_by?: string;
|
||||
}
|
||||
|
||||
export type AuthType = "none" | "api-key" | "bearer" | "basic" | "oauth2";
|
||||
|
||||
export interface ExternalApiConnection {
|
||||
id?: number;
|
||||
connection_name: string;
|
||||
description?: string;
|
||||
base_url: string;
|
||||
default_headers: Record<string, string>;
|
||||
auth_type: AuthType;
|
||||
auth_config?: {
|
||||
keyLocation?: "header" | "query";
|
||||
keyName?: string;
|
||||
keyValue?: string;
|
||||
token?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
clientId?: string;
|
||||
clientSecret?: string;
|
||||
tokenUrl?: string;
|
||||
accessToken?: string;
|
||||
};
|
||||
timeout?: number;
|
||||
company_code: string;
|
||||
is_active: string;
|
||||
created_date?: Date;
|
||||
created_by?: string;
|
||||
updated_date?: Date;
|
||||
updated_by?: string;
|
||||
}
|
||||
|
||||
export interface ExternalDbConnectionFilter {
|
||||
db_type?: string;
|
||||
is_active?: string;
|
||||
@@ -209,7 +239,7 @@ export class ExternalDbConnectionAPI {
|
||||
try {
|
||||
const response = await apiClient.post<ApiResponse<ConnectionTestResult>>(
|
||||
`${this.BASE_PATH}/${connectionId}/test`,
|
||||
password ? { password } : undefined
|
||||
password ? { password } : undefined,
|
||||
);
|
||||
|
||||
if (!response.data.success) {
|
||||
@@ -220,10 +250,12 @@ export class ExternalDbConnectionAPI {
|
||||
};
|
||||
}
|
||||
|
||||
return response.data.data || {
|
||||
success: true,
|
||||
message: response.data.message || "연결 테스트가 완료되었습니다.",
|
||||
};
|
||||
return (
|
||||
response.data.data || {
|
||||
success: true,
|
||||
message: response.data.message || "연결 테스트가 완료되었습니다.",
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("연결 테스트 오류:", error);
|
||||
|
||||
@@ -246,9 +278,7 @@ export class ExternalDbConnectionAPI {
|
||||
*/
|
||||
static async getTables(connectionId: number): Promise<ApiResponse<string[]>> {
|
||||
try {
|
||||
const response = await apiClient.get<ApiResponse<string[]>>(
|
||||
`${this.BASE_PATH}/${connectionId}/tables`
|
||||
);
|
||||
const response = await apiClient.get<ApiResponse<string[]>>(`${this.BASE_PATH}/${connectionId}/tables`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("테이블 목록 조회 오류:", error);
|
||||
@@ -260,7 +290,7 @@ export class ExternalDbConnectionAPI {
|
||||
try {
|
||||
console.log("컬럼 정보 API 요청:", `${this.BASE_PATH}/${connectionId}/tables/${tableName}/columns`);
|
||||
const response = await apiClient.get<ApiResponse<any[]>>(
|
||||
`${this.BASE_PATH}/${connectionId}/tables/${tableName}/columns`
|
||||
`${this.BASE_PATH}/${connectionId}/tables/${tableName}/columns`,
|
||||
);
|
||||
console.log("컬럼 정보 API 응답:", response.data);
|
||||
return response.data;
|
||||
@@ -273,10 +303,7 @@ export class ExternalDbConnectionAPI {
|
||||
static async executeQuery(connectionId: number, query: string): Promise<ApiResponse<any[]>> {
|
||||
try {
|
||||
console.log("API 요청:", `${this.BASE_PATH}/${connectionId}/execute`, { query });
|
||||
const response = await apiClient.post<ApiResponse<any[]>>(
|
||||
`${this.BASE_PATH}/${connectionId}/execute`,
|
||||
{ query }
|
||||
);
|
||||
const response = await apiClient.post<ApiResponse<any[]>>(`${this.BASE_PATH}/${connectionId}/execute`, { query });
|
||||
console.log("API 응답:", response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
@@ -284,4 +311,45 @@ export class ExternalDbConnectionAPI {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* REST API 연결 목록 조회 (외부 커넥션에서)
|
||||
*/
|
||||
static async getApiConnections(filter: { is_active?: string } = {}): Promise<ExternalApiConnection[]> {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
if (filter.is_active) params.append("is_active", filter.is_active);
|
||||
|
||||
const response = await apiClient.get<ApiResponse<ExternalApiConnection[]>>(
|
||||
`/external-rest-api-connections?${params.toString()}`,
|
||||
);
|
||||
|
||||
if (!response.data.success) {
|
||||
throw new Error(response.data.message || "API 연결 목록 조회에 실패했습니다.");
|
||||
}
|
||||
|
||||
return response.data.data || [];
|
||||
} catch (error) {
|
||||
console.error("API 연결 목록 조회 오류:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 REST API 연결 조회
|
||||
*/
|
||||
static async getApiConnectionById(id: number): Promise<ExternalApiConnection | null> {
|
||||
try {
|
||||
const response = await apiClient.get<ApiResponse<ExternalApiConnection>>(`/external-rest-api-connections/${id}`);
|
||||
|
||||
if (!response.data.success || !response.data.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.error("API 연결 조회 오류:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user