snp-global/frontend/src/api/bypassApi.ts
HYOJIN fab03a31bb feat(swagger): Swagger 응답 스키마 자동 생성 및 API 문서 개선 (#14)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 15:40:49 +09:00

111 lines
3.3 KiB
TypeScript

// API 응답 타입
interface ApiResponse<T> {
success: boolean;
message: string;
data: T;
errorCode?: string;
}
// 타입 정의
export interface BypassParamDto {
id?: number;
paramName: string;
paramType: string; // STRING, INTEGER, LONG, BOOLEAN
paramIn: string; // PATH, QUERY, BODY
required: boolean;
description: string;
example: string; // Swagger @Parameter example 값
sortOrder: number;
}
export interface BypassConfigRequest {
domainName: string;
displayName: string;
webclientBean: string;
externalPath: string;
httpMethod: string;
description: string;
params: BypassParamDto[];
}
export interface BypassConfigResponse {
id: number;
domainName: string;
endpointName: string;
displayName: string;
webclientBean: string;
externalPath: string;
httpMethod: string;
description: string;
generated: boolean;
generatedAt: string | null;
responseSchemaClass: string | null;
createdAt: string;
updatedAt: string;
params: BypassParamDto[];
}
export interface CodeGenerationResult {
controllerPath: string;
servicePaths: string[];
message: string;
}
export interface WebClientBeanInfo {
name: string;
description: string;
}
// BASE URL
const BASE = '/snp-global/api/bypass-config';
// 헬퍼 함수 (batchApi.ts 패턴과 동일)
async function fetchJson<T>(url: string): Promise<T> {
const res = await fetch(url);
if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`);
return res.json();
}
async function postJson<T>(url: string, body?: unknown): Promise<T> {
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: body != null ? JSON.stringify(body) : undefined,
});
if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`);
return res.json();
}
async function putJson<T>(url: string, body?: unknown): Promise<T> {
const res = await fetch(url, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: body != null ? JSON.stringify(body) : undefined,
});
if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`);
return res.json();
}
async function deleteJson<T>(url: string): Promise<T> {
const res = await fetch(url, { method: 'DELETE' });
if (!res.ok) throw new Error(`API Error: ${res.status} ${res.statusText}`);
return res.json();
}
export const bypassApi = {
getConfigs: () =>
fetchJson<ApiResponse<BypassConfigResponse[]>>(BASE),
getConfig: (id: number) =>
fetchJson<ApiResponse<BypassConfigResponse>>(`${BASE}/${id}`),
createConfig: (data: BypassConfigRequest) =>
postJson<ApiResponse<BypassConfigResponse>>(BASE, data),
updateConfig: (id: number, data: BypassConfigRequest) =>
putJson<ApiResponse<BypassConfigResponse>>(`${BASE}/${id}`, data),
deleteConfig: (id: number) =>
deleteJson<ApiResponse<void>>(`${BASE}/${id}`),
generateCode: (id: number, force = false) =>
postJson<ApiResponse<CodeGenerationResult>>(`${BASE}/${id}/generate?force=${force}`),
getWebclientBeans: () =>
fetchJson<ApiResponse<WebClientBeanInfo[]>>(`${BASE}/webclient-beans`),
};