Files
frontend/apps/sn/app/components/lib/api/index.ts
T
swcho a7216dfcc6 feat:
- 침입수 분석 화면 변수명 오타 수정
- 분석결과 화면 수정 및 조회 기능 구현, 파일 다운로드, 삭제 구현중
- 중점우수토실 상세정보 화면 구현
- verticalTable.tsx에 테이블 추가
- contentLayout.tsx에 className prop 추가
- fileDownload.ts에 BASE_URL 추가
2025-06-05 17:13:25 +09:00

68 lines
2.1 KiB
TypeScript

const BASE_URL = process.env.NEXT_PUBLIC_SEWERAGE_API_URL || '';
export const postData = async (url: string, data: object): Promise<any> => {
const options: RequestInit = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
};
const res = await fetch(`${BASE_URL}/${url}`, options);
if (res.ok) {
const resData = await res.json();
return resData;
// const text = await res.text();
// if (text) {
// return JSON.parse(text); // JSON 데이터가 있으면 파싱하여 반환
// }
// return true; // 응답 본문이 비어 있으면 true 반환
}
};
export const postMutiPart = async (url: string, data: FormData): Promise<any> => {
const options: RequestInit = {
method: "POST",
body: data,
};
const res = await fetch(`${BASE_URL}/${url}`, options);
const resData = await res.json();
return resData;
};
export const putData = async (url: string, data: object): Promise<any> => {
const options: RequestInit = {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
};
const res = await fetch(`${BASE_URL}/${url}`, options);
const resData = await res.json();
return resData;
};
export const getData = async (url: string, data?: object): Promise<any> => {
const res = await fetch(url.startsWith('/') ? `${url}` : `${BASE_URL}/${url}`, {
method: "GET",
});
if (res.ok) {
const data = await res.json();
return data;
}
throw new Error('Failed to fetch data');
};
export const deleteData = async (url: string, data?: object): Promise<any> => {
const options: RequestInit = {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: data ? JSON.stringify(data) : undefined,
};
const res = await fetch(url.startsWith('/') ? `${url}` : `${BASE_URL}/${url}`, options);
if (res.status === 204) return true
return res;
};