- 카테고리 트리 컨트롤러에 전체 카테고리 키 목록 조회 라우트 추가: GET /api/category-tree/test/all-category-keys - 카테고리 트리 서비스에 전체 카테고리 키 목록 조회 메서드 구현: 모든 테이블과 컬럼 조합을 반환 - 채번규칙 컨트롤러에서 폼 데이터 처리 기능 추가: 코드 미리보기 시 카테고리 기반 폼 데이터 사용 - 관련 API 클라이언트 및 타입 정의 업데이트: 카테고리 키 조회 및 채번규칙 API에 대한 요청 처리 개선 이로 인해 카테고리 관리 및 채번규칙 테스트의 효율성이 향상되었습니다.
208 lines
5.6 KiB
TypeScript
208 lines
5.6 KiB
TypeScript
/**
|
|
* 카테고리 트리 API 클라이언트 (테스트용)
|
|
* - 트리 구조 CRUD 지원
|
|
*/
|
|
|
|
import { apiClient } from "./client";
|
|
|
|
// 카테고리 값 타입
|
|
export interface CategoryValue {
|
|
valueId: number;
|
|
tableName: string;
|
|
columnName: string;
|
|
valueCode: string;
|
|
valueLabel: string;
|
|
valueOrder: number;
|
|
parentValueId: number | null;
|
|
depth: number; // 1=대분류, 2=중분류, 3=소분류
|
|
path: string | null;
|
|
description: string | null;
|
|
color: string | null;
|
|
icon: string | null;
|
|
isActive: boolean;
|
|
isDefault: boolean;
|
|
companyCode: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
// 트리 구조용
|
|
children?: CategoryValue[];
|
|
}
|
|
|
|
// 카테고리 값 생성 입력
|
|
export interface CreateCategoryValueInput {
|
|
tableName: string;
|
|
columnName: string;
|
|
valueCode: string;
|
|
valueLabel: string;
|
|
valueOrder?: number;
|
|
parentValueId?: number | null;
|
|
description?: string;
|
|
color?: string;
|
|
icon?: string;
|
|
isActive?: boolean;
|
|
isDefault?: boolean;
|
|
}
|
|
|
|
// 카테고리 값 수정 입력
|
|
export interface UpdateCategoryValueInput {
|
|
valueCode?: string;
|
|
valueLabel?: string;
|
|
valueOrder?: number;
|
|
parentValueId?: number | null;
|
|
description?: string;
|
|
color?: string;
|
|
icon?: string;
|
|
isActive?: boolean;
|
|
isDefault?: boolean;
|
|
}
|
|
|
|
// API 응답 타입
|
|
export interface ApiResponse<T> {
|
|
success: boolean;
|
|
data?: T;
|
|
error?: string;
|
|
message?: string;
|
|
}
|
|
|
|
/**
|
|
* 카테고리 트리 조회
|
|
*/
|
|
export async function getCategoryTree(
|
|
tableName: string,
|
|
columnName: string
|
|
): Promise<ApiResponse<CategoryValue[]>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/${tableName}/${columnName}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 트리 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 목록 조회 (플랫)
|
|
*/
|
|
export async function getCategoryList(
|
|
tableName: string,
|
|
columnName: string
|
|
): Promise<ApiResponse<CategoryValue[]>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/${tableName}/${columnName}/flat`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 목록 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 단일 조회
|
|
*/
|
|
export async function getCategoryValue(valueId: number): Promise<ApiResponse<CategoryValue>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/value/${valueId}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 생성
|
|
*/
|
|
export async function createCategoryValue(
|
|
input: CreateCategoryValueInput
|
|
): Promise<ApiResponse<CategoryValue>> {
|
|
try {
|
|
const response = await apiClient.post("/category-tree/test/value", input);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 생성 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 수정
|
|
*/
|
|
export async function updateCategoryValue(
|
|
valueId: number,
|
|
input: UpdateCategoryValueInput
|
|
): Promise<ApiResponse<CategoryValue>> {
|
|
try {
|
|
const response = await apiClient.put(`/category-tree/test/value/${valueId}`, input);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 수정 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 카테고리 값 삭제
|
|
*/
|
|
export async function deleteCategoryValue(valueId: number): Promise<ApiResponse<void>> {
|
|
try {
|
|
const response = await apiClient.delete(`/category-tree/test/value/${valueId}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 값 삭제 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 테이블의 카테고리 컬럼 목록 조회
|
|
*/
|
|
export async function getCategoryColumns(
|
|
tableName: string
|
|
): Promise<ApiResponse<{ columnName: string; columnLabel: string }[]>> {
|
|
try {
|
|
const response = await apiClient.get(`/category-tree/test/columns/${tableName}`);
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "카테고리 컬럼 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 전체 카테고리 키 목록 조회 (모든 테이블.컬럼 조합)
|
|
*/
|
|
export async function getAllCategoryKeys(): Promise<ApiResponse<{ tableName: string; columnName: string }[]>> {
|
|
try {
|
|
const response = await apiClient.get("/category-tree/test/all-category-keys");
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
const err = error as { response?: { data?: { error?: string } }; message?: string };
|
|
return {
|
|
success: false,
|
|
error: err.response?.data?.error || err.message || "전체 카테고리 키 조회 실패",
|
|
};
|
|
}
|
|
}
|
|
|