카테고리 트리 기능 추가 및 관련 API 구현
- 카테고리 트리 컨트롤러와 서비스 추가: 트리 구조를 지원하는 카테고리 값 관리 기능을 구현하였습니다. - 카테고리 트리 API 클라이언트 추가: CRUD 작업을 위한 API 클라이언트를 구현하였습니다. - 카테고리 값 관리 컴포넌트 및 설정 패널 추가: 사용자 인터페이스에서 카테고리 값을 관리할 수 있도록 트리 구조 기반의 컴포넌트를 추가하였습니다. - 관련 라우트 및 레지스트리 업데이트: 카테고리 트리 관련 라우트를 추가하고, 컴포넌트 레지스트리에 등록하였습니다. 이로 인해 카테고리 관리의 효율성이 향상되었습니다.
This commit is contained in:
191
frontend/lib/api/categoryTree.ts
Normal file
191
frontend/lib/api/categoryTree.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* 카테고리 트리 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 || "카테고리 컬럼 조회 실패",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user