feat(order-management): Mock → API 연동 및 common-codes 유틸리티 추가
- common-codes.ts 신규 생성 (공용 코드 조회 유틸리티) - getCommonCodes(), getCommonCodeOptions() 기본 함수 - getOrderStatusOptions(), getOrderTypeOptions() 등 편의 함수 - order-management/actions.ts Mock 데이터 → 실제 API 연동 - 상태 변환 함수 (Frontend ↔ Backend 매핑) - getOrderList(), getOrderStats(), createOrder(), updateOrder() 등 구현 - lib/api/index.ts에 common-codes 모듈 export 추가
This commit is contained in:
121
src/lib/api/common-codes.ts
Normal file
121
src/lib/api/common-codes.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
'use server';
|
||||
|
||||
import { apiClient } from './index';
|
||||
|
||||
// ========================================
|
||||
// 공통 코드 타입
|
||||
// ========================================
|
||||
|
||||
export interface CommonCode {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
sort_order: number;
|
||||
attributes: Record<string, unknown> | null;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// 공통 코드 조회 함수
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* 특정 그룹의 공통 코드 목록 조회
|
||||
* GET /api/v1/settings/common/{group}
|
||||
*/
|
||||
export async function getCommonCodes(group: string): Promise<{
|
||||
success: boolean;
|
||||
data?: CommonCode[];
|
||||
error?: string;
|
||||
}> {
|
||||
try {
|
||||
const response = await apiClient.get<CommonCode[]>(`/settings/common/${group}`);
|
||||
return { success: true, data: response };
|
||||
} catch (error) {
|
||||
console.error(`공통코드 조회 오류 (${group}):`, error);
|
||||
return { success: false, error: '공통코드를 불러오는데 실패했습니다.' };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 공통 코드 옵션 형태로 변환
|
||||
* Select/ComboBox 등에서 사용
|
||||
*/
|
||||
export async function getCommonCodeOptions(group: string): Promise<{
|
||||
success: boolean;
|
||||
data?: { value: string; label: string }[];
|
||||
error?: string;
|
||||
}> {
|
||||
const result = await getCommonCodes(group);
|
||||
|
||||
if (!result.success || !result.data) {
|
||||
return { success: false, error: result.error };
|
||||
}
|
||||
|
||||
const options = result.data.map((code) => ({
|
||||
value: code.code,
|
||||
label: code.name,
|
||||
}));
|
||||
|
||||
return { success: true, data: options };
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// 자주 사용하는 코드 그룹 함수
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* 수주 상태 코드 조회
|
||||
*/
|
||||
export async function getOrderStatusCodes() {
|
||||
return getCommonCodes('order_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* 수주 상태 옵션 조회
|
||||
*/
|
||||
export async function getOrderStatusOptions() {
|
||||
return getCommonCodeOptions('order_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* 수주 유형 코드 조회
|
||||
*/
|
||||
export async function getOrderTypeCodes() {
|
||||
return getCommonCodes('order_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* 수주 유형 옵션 조회
|
||||
*/
|
||||
export async function getOrderTypeOptions() {
|
||||
return getCommonCodeOptions('order_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* 거래처 유형 코드 조회
|
||||
*/
|
||||
export async function getClientTypeCodes() {
|
||||
return getCommonCodes('client_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* 거래처 유형 옵션 조회
|
||||
*/
|
||||
export async function getClientTypeOptions() {
|
||||
return getCommonCodeOptions('client_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 유형 코드 조회
|
||||
*/
|
||||
export async function getItemTypeCodes() {
|
||||
return getCommonCodes('item_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 유형 옵션 조회
|
||||
*/
|
||||
export async function getItemTypeOptions() {
|
||||
return getCommonCodeOptions('item_type');
|
||||
}
|
||||
Reference in New Issue
Block a user