2025-11-05 15:23:57 +09:00
|
|
|
import { apiClient } from "./client";
|
|
|
|
|
import {
|
|
|
|
|
TableCategoryValue,
|
|
|
|
|
CategoryColumn,
|
|
|
|
|
} from "@/types/tableCategoryValue";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테이블의 카테고리 컬럼 목록 조회
|
|
|
|
|
*/
|
|
|
|
|
export async function getCategoryColumns(tableName: string) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await apiClient.get<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
data: CategoryColumn[];
|
|
|
|
|
}>(`/table-categories/${tableName}/columns`);
|
|
|
|
|
return response.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("카테고리 컬럼 조회 실패:", error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-11 14:32:00 +09:00
|
|
|
* 카테고리 값 목록 조회 (메뉴 스코프)
|
|
|
|
|
*
|
|
|
|
|
* @param tableName 테이블명
|
|
|
|
|
* @param columnName 컬럼명
|
|
|
|
|
* @param includeInactive 비활성 값 포함 여부
|
|
|
|
|
* @param menuObjid 메뉴 OBJID (선택사항, 제공 시 형제 메뉴의 카테고리 값 포함)
|
2025-11-05 15:23:57 +09:00
|
|
|
*/
|
|
|
|
|
export async function getCategoryValues(
|
|
|
|
|
tableName: string,
|
|
|
|
|
columnName: string,
|
2025-11-11 14:32:00 +09:00
|
|
|
includeInactive: boolean = false,
|
|
|
|
|
menuObjid?: number
|
2025-11-05 15:23:57 +09:00
|
|
|
) {
|
|
|
|
|
try {
|
2025-11-11 14:32:00 +09:00
|
|
|
const params: any = { includeInactive };
|
|
|
|
|
if (menuObjid) {
|
|
|
|
|
params.menuObjid = menuObjid;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 15:23:57 +09:00
|
|
|
const response = await apiClient.get<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
data: TableCategoryValue[];
|
|
|
|
|
}>(`/table-categories/${tableName}/${columnName}/values`, {
|
2025-11-11 14:32:00 +09:00
|
|
|
params,
|
2025-11-05 15:23:57 +09:00
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("카테고리 값 조회 실패:", error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-11 14:32:00 +09:00
|
|
|
* 카테고리 값 추가 (메뉴 스코프)
|
|
|
|
|
*
|
|
|
|
|
* @param value 카테고리 값 정보
|
|
|
|
|
* @param menuObjid 메뉴 OBJID (필수)
|
2025-11-05 15:23:57 +09:00
|
|
|
*/
|
2025-11-11 14:32:00 +09:00
|
|
|
export async function addCategoryValue(
|
|
|
|
|
value: TableCategoryValue,
|
|
|
|
|
menuObjid: number
|
|
|
|
|
) {
|
2025-11-05 15:23:57 +09:00
|
|
|
try {
|
|
|
|
|
const response = await apiClient.post<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
data: TableCategoryValue;
|
2025-11-11 14:32:00 +09:00
|
|
|
}>("/table-categories/values", {
|
|
|
|
|
...value,
|
|
|
|
|
menuObjid, // ← menuObjid 포함
|
|
|
|
|
});
|
2025-11-05 15:23:57 +09:00
|
|
|
return response.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("카테고리 값 추가 실패:", error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 카테고리 값 수정
|
|
|
|
|
*/
|
|
|
|
|
export async function updateCategoryValue(
|
|
|
|
|
valueId: number,
|
|
|
|
|
updates: Partial<TableCategoryValue>
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await apiClient.put<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
data: TableCategoryValue;
|
|
|
|
|
}>(`/table-categories/values/${valueId}`, updates);
|
|
|
|
|
return response.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("카테고리 값 수정 실패:", error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 카테고리 값 삭제
|
|
|
|
|
*/
|
|
|
|
|
export async function deleteCategoryValue(valueId: number) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await apiClient.delete<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
}>(`/table-categories/values/${valueId}`);
|
|
|
|
|
return response.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("카테고리 값 삭제 실패:", error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 카테고리 값 일괄 삭제
|
|
|
|
|
*/
|
|
|
|
|
export async function bulkDeleteCategoryValues(valueIds: number[]) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await apiClient.post<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
}>("/table-categories/values/bulk-delete", { valueIds });
|
|
|
|
|
return response.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("카테고리 값 일괄 삭제 실패:", error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 카테고리 값 순서 변경
|
|
|
|
|
*/
|
|
|
|
|
export async function reorderCategoryValues(orderedValueIds: number[]) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await apiClient.post<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
}>("/table-categories/values/reorder", { orderedValueIds });
|
|
|
|
|
return response.data;
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("카테고리 값 순서 변경 실패:", error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|