172 lines
4.6 KiB
TypeScript
172 lines
4.6 KiB
TypeScript
/**
|
|
* 회사 관리 API 호출 함수들
|
|
*/
|
|
|
|
import { Company, CompanyFormData } from "@/types/company";
|
|
import { apiClient } from "./client";
|
|
|
|
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://39.117.244.52:8080/api";
|
|
|
|
// API 응답 타입 정의
|
|
interface ApiResponse<T = any> {
|
|
success: boolean;
|
|
message?: string;
|
|
data?: T;
|
|
total?: number;
|
|
errorCode?: string;
|
|
}
|
|
|
|
/**
|
|
* 회사 목록 조회
|
|
*/
|
|
export async function getCompanyList(params?: { company_name?: string; status?: string }): Promise<Company[]> {
|
|
const searchParams = new URLSearchParams();
|
|
|
|
if (params?.company_name) {
|
|
searchParams.append("company_name", params.company_name);
|
|
}
|
|
if (params?.status && params.status !== "all") {
|
|
searchParams.append("status", params.status);
|
|
}
|
|
|
|
const queryString = searchParams.toString();
|
|
// 실제 데이터베이스에서 회사 목록 조회하는 엔드포인트 사용
|
|
const endpoint = `/admin/companies/db${queryString ? `?${queryString}` : ""}`;
|
|
|
|
console.log("🔍 실제 DB에서 회사 목록 조회 API 호출:", endpoint);
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 회사 단건 조회
|
|
*/
|
|
export async function getCompanyInfo(companyCode: string): Promise<Company> {
|
|
const response = await apiClient.get(`/admin/companies/${companyCode}`);
|
|
|
|
if (response.data.success && response.data.data) {
|
|
return response.data.data;
|
|
}
|
|
|
|
throw new Error(response.data.message || "회사 정보 조회에 실패했습니다.");
|
|
}
|
|
|
|
/**
|
|
* 회사 등록
|
|
*/
|
|
export async function createCompany(formData: CompanyFormData): Promise<Company> {
|
|
console.log("회사 등록 요청:", formData);
|
|
|
|
const response = await apiClient.post("/admin/companies", formData);
|
|
|
|
if (response.data.success && response.data.data) {
|
|
console.log("회사 등록 완료:", {
|
|
code: response.data.data.company_code,
|
|
name: response.data.data.company_name,
|
|
writer: response.data.data.writer,
|
|
});
|
|
|
|
return response.data.data;
|
|
}
|
|
|
|
throw new Error(response.data.message || "회사 등록에 실패했습니다.");
|
|
}
|
|
|
|
/**
|
|
* 회사 정보 수정
|
|
*/
|
|
export async function updateCompany(
|
|
companyCode: string,
|
|
formData: Partial<CompanyFormData> & { status?: string },
|
|
): Promise<Company> {
|
|
const response = await apiClient.put(`/admin/companies/${companyCode}`, formData);
|
|
|
|
if (response.data.success && response.data.data) {
|
|
return response.data.data;
|
|
}
|
|
|
|
throw new Error(response.data.message || "회사 정보 수정에 실패했습니다.");
|
|
}
|
|
|
|
/**
|
|
* 회사 삭제
|
|
*/
|
|
export async function deleteCompany(companyCode: string): Promise<void> {
|
|
const response = await apiClient.delete(`/admin/companies/${companyCode}`);
|
|
|
|
if (!response.data.success) {
|
|
throw new Error(response.data.message || "회사 삭제에 실패했습니다.");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 회사별 디스크 사용량 조회
|
|
*/
|
|
export async function getCompanyDiskUsage(companyCode: string): Promise<{
|
|
companyCode: string;
|
|
fileCount: number;
|
|
totalSize: number;
|
|
totalSizeMB: number;
|
|
lastChecked: string;
|
|
}> {
|
|
const response = await apiClient.get(`/company-management/${companyCode}/disk-usage`);
|
|
|
|
if (response.data.success && response.data.data) {
|
|
return response.data.data;
|
|
}
|
|
|
|
throw new Error(response.data.message || "디스크 사용량 조회에 실패했습니다.");
|
|
}
|
|
|
|
/**
|
|
* 전체 회사 디스크 사용량 조회
|
|
*/
|
|
export async function getAllCompaniesDiskUsage(): Promise<{
|
|
companies: Array<{
|
|
companyCode: string;
|
|
fileCount: number;
|
|
totalSize: number;
|
|
totalSizeMB: number;
|
|
}>;
|
|
summary: {
|
|
totalCompanies: number;
|
|
totalFiles: number;
|
|
totalSize: number;
|
|
totalSizeMB: number;
|
|
};
|
|
lastChecked: string;
|
|
}> {
|
|
const response = await apiClient.get("/company-management/disk-usage/all");
|
|
|
|
if (response.data.success && response.data.data) {
|
|
return response.data.data;
|
|
}
|
|
|
|
throw new Error(response.data.message || "전체 디스크 사용량 조회에 실패했습니다.");
|
|
}
|
|
|
|
/**
|
|
* 회사 관리 API 객체 (통합)
|
|
*/
|
|
export const companyAPI = {
|
|
getList: getCompanyList,
|
|
getInfo: getCompanyInfo,
|
|
create: createCompany,
|
|
update: updateCompany,
|
|
delete: deleteCompany,
|
|
getDiskUsage: getCompanyDiskUsage,
|
|
getAllDiskUsage: getAllCompaniesDiskUsage,
|
|
};
|