회사관리, 메뉴관리 수정,삭제 기능
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios, { AxiosResponse, AxiosError } from "axios";
|
||||
|
||||
// API 기본 URL 설정
|
||||
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080/api";
|
||||
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080";
|
||||
|
||||
// JWT 토큰 관리 유틸리티
|
||||
const TokenManager = {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import { Company, CompanyFormData } from "@/types/company";
|
||||
import { apiClient } from "./client";
|
||||
|
||||
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "/api";
|
||||
|
||||
@@ -15,31 +16,6 @@ interface ApiResponse<T = any> {
|
||||
errorCode?: string;
|
||||
}
|
||||
|
||||
// API 호출 헬퍼 함수
|
||||
async function apiCall<T = any>(endpoint: string, options: RequestInit = {}): Promise<ApiResponse<T>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
credentials: "include", // 세션 쿠키를 포함
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
...options,
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || `HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`API Error [${endpoint}]:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 회사 목록 조회
|
||||
*/
|
||||
@@ -54,28 +30,37 @@ export async function getCompanyList(params?: { company_name?: string; status?:
|
||||
}
|
||||
|
||||
const queryString = searchParams.toString();
|
||||
const endpoint = `/admin/companies${queryString ? `?${queryString}` : ""}`;
|
||||
// 실제 데이터베이스에서 회사 목록 조회하는 엔드포인트 사용
|
||||
const endpoint = `/admin/companies/db${queryString ? `?${queryString}` : ""}`;
|
||||
|
||||
const response = await apiCall<Company[]>(endpoint);
|
||||
console.log("🔍 실제 DB에서 회사 목록 조회 API 호출:", endpoint);
|
||||
|
||||
if (response.success && response.data) {
|
||||
return response.data;
|
||||
try {
|
||||
const response = await apiClient.get(endpoint);
|
||||
|
||||
if (response.data.success && response.data.data) {
|
||||
console.log("✅ 실제 DB에서 회사 목록 조회 성공:", response.data.data.length, "개");
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
throw new Error(response.data.message || "회사 목록 조회에 실패했습니다.");
|
||||
} catch (error) {
|
||||
console.error("❌ 실제 DB에서 회사 목록 조회 실패:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
throw new Error(response.message || "회사 목록 조회에 실패했습니다.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 회사 단건 조회
|
||||
*/
|
||||
export async function getCompanyInfo(companyCode: string): Promise<Company> {
|
||||
const response = await apiCall<Company>(`/admin/companies/${companyCode}`);
|
||||
const response = await apiClient.get(`/admin/companies/${companyCode}`);
|
||||
|
||||
if (response.success && response.data) {
|
||||
return response.data;
|
||||
if (response.data.success && response.data.data) {
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
throw new Error(response.message || "회사 정보 조회에 실패했습니다.");
|
||||
throw new Error(response.data.message || "회사 정보 조회에 실패했습니다.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,22 +69,19 @@ export async function getCompanyInfo(companyCode: string): Promise<Company> {
|
||||
export async function createCompany(formData: CompanyFormData): Promise<Company> {
|
||||
console.log("회사 등록 요청:", formData);
|
||||
|
||||
const response = await apiCall<Company>("/admin/companies", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(formData),
|
||||
});
|
||||
const response = await apiClient.post("/admin/companies", formData);
|
||||
|
||||
if (response.success && response.data) {
|
||||
if (response.data.success && response.data.data) {
|
||||
console.log("회사 등록 완료:", {
|
||||
code: response.data.company_code,
|
||||
name: response.data.company_name,
|
||||
writer: response.data.writer,
|
||||
code: response.data.data.company_code,
|
||||
name: response.data.data.company_name,
|
||||
writer: response.data.data.writer,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
throw new Error(response.message || "회사 등록에 실패했습니다.");
|
||||
throw new Error(response.data.message || "회사 등록에 실패했습니다.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,28 +91,23 @@ export async function updateCompany(
|
||||
companyCode: string,
|
||||
formData: Partial<CompanyFormData> & { status?: string },
|
||||
): Promise<Company> {
|
||||
const response = await apiCall<Company>(`/admin/companies/${companyCode}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(formData),
|
||||
});
|
||||
const response = await apiClient.put(`/admin/companies/${companyCode}`, formData);
|
||||
|
||||
if (response.success && response.data) {
|
||||
return response.data;
|
||||
if (response.data.success && response.data.data) {
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
throw new Error(response.message || "회사 정보 수정에 실패했습니다.");
|
||||
throw new Error(response.data.message || "회사 정보 수정에 실패했습니다.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 회사 삭제
|
||||
*/
|
||||
export async function deleteCompany(companyCode: string): Promise<void> {
|
||||
const response = await apiCall(`/admin/companies/${companyCode}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
const response = await apiClient.delete(`/admin/companies/${companyCode}`);
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(response.message || "회사 삭제에 실패했습니다.");
|
||||
if (!response.data.success) {
|
||||
throw new Error(response.data.message || "회사 삭제에 실패했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,12 @@ export const menuApi = {
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 메뉴 수정
|
||||
updateMenu: async (menuId: string, menuData: MenuFormData): Promise<ApiResponse<void>> => {
|
||||
const response = await apiClient.put(`/admin/menus/${menuId}`, menuData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 메뉴 삭제
|
||||
deleteMenu: async (menuId: string): Promise<ApiResponse<void>> => {
|
||||
const response = await apiClient.delete(`/admin/menus/${menuId}`);
|
||||
@@ -139,7 +145,16 @@ export const menuApi = {
|
||||
menuCode?: string;
|
||||
keyType?: string;
|
||||
}): Promise<ApiResponse<LangKey[]>> => {
|
||||
const response = await apiClient.get("/multilang/keys", { params });
|
||||
return response.data;
|
||||
console.log("🔍 다국어 키 목록 조회 API 호출:", "/admin/multilang/keys", params);
|
||||
|
||||
try {
|
||||
// Node.js 백엔드의 실제 라우팅과 일치하도록 수정
|
||||
const response = await apiClient.get("/admin/multilang/keys", { params });
|
||||
console.log("✅ 다국어 키 목록 조회 성공:", response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("❌ 다국어 키 목록 조회 실패:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user