From aa074ad148b50e396c20b020c5777c3e937668d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=98=84=EC=A1=B0?= Date: Thu, 12 Sep 2024 10:41:28 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=8F=B4=EB=8D=94,=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EA=B4=80=EB=A0=A8=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/folderApi.ts | 109 ++++++++++++++++++++++++++++++ frontend/src/api/imageApi.ts | 123 ++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 frontend/src/api/folderApi.ts create mode 100644 frontend/src/api/imageApi.ts diff --git a/frontend/src/api/folderApi.ts b/frontend/src/api/folderApi.ts new file mode 100644 index 0000000..e2cfab2 --- /dev/null +++ b/frontend/src/api/folderApi.ts @@ -0,0 +1,109 @@ +import api from '@/api/axiosConfig'; +import { AxiosError } from 'axios'; +import { FolderResponseDTO, FolderRequestDTO, BaseResponse } from '@/types'; + +export const fetchFolderApi = async ( + projectId: number, + folderId: number, + memberId: number +): Promise> => { + try { + const response = await api.get(`/api/projects/${projectId}/folders/${folderId}`, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('폴더 조회 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const updateFolderApi = async ( + projectId: number, + folderId: number, + memberId: number, + folderData: FolderRequestDTO +): Promise> => { + try { + const response = await api.put(`/api/projects/${projectId}/folders/${folderId}`, folderData, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('폴더 수정 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const deleteFolderApi = async ( + projectId: number, + folderId: number, + memberId: number +): Promise> => { + try { + const response = await api.delete(`/api/projects/${projectId}/folders/${folderId}`, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('폴더 삭제 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const createFolderApi = async ( + projectId: number, + memberId: number, + folderData: FolderRequestDTO +): Promise> => { + try { + const response = await api.post(`/api/projects/${projectId}/folders`, folderData, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('폴더 생성 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const fetchFolderReviewListApi = async ( + projectId: number, + folderId: number, + memberId: number +): Promise> => { + try { + const response = await api.get(`/api/projects/${projectId}/folders/${folderId}/review`, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('리뷰해야 할 폴더 목록 조회 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; diff --git a/frontend/src/api/imageApi.ts b/frontend/src/api/imageApi.ts new file mode 100644 index 0000000..30c70b4 --- /dev/null +++ b/frontend/src/api/imageApi.ts @@ -0,0 +1,123 @@ +import api from '@/api/axiosConfig'; +import { AxiosError } from 'axios'; +import { ImageResponseDTO, ImageMoveRequestDTO, ImageStatusChangeRequestDTO, BaseResponse } from '@/types'; + +export const fetchImageApi = async ( + projectId: number, + folderId: number, + imageId: number, + memberId: number +): Promise> => { + try { + const response = await api.get(`/api/projects/${projectId}/folders/${folderId}/images/${imageId}`, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('이미지 조회 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const moveImageApi = async ( + projectId: number, + folderId: number, + imageId: number, + memberId: number, + moveRequest: ImageMoveRequestDTO +): Promise> => { + try { + const response = await api.put(`/api/projects/${projectId}/folders/${folderId}/images/${imageId}`, moveRequest, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('이미지 폴더 이동 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const deleteImageApi = async ( + projectId: number, + folderId: number, + imageId: number, + memberId: number +): Promise> => { + try { + const response = await api.delete(`/api/projects/${projectId}/folders/${folderId}/images/${imageId}`, { + params: { memberId }, + withCredentials: true, + }); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('이미지 삭제 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const changeImageStatusApi = async ( + projectId: number, + folderId: number, + imageId: number, + memberId: number, + statusChangeRequest: ImageStatusChangeRequestDTO +): Promise> => { + try { + const response = await api.put( + `/api/projects/${projectId}/folders/${folderId}/images/${imageId}/status`, + statusChangeRequest, + { + params: { memberId }, + withCredentials: true, + } + ); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('이미지 상태 변경 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +}; + +export const uploadImageListApi = async ( + projectId: number, + folderId: number, + memberId: number, + imageList: string[] +): Promise> => { + try { + const response = await api.post( + `/api/projects/${projectId}/folders/${folderId}/images`, + { imageList }, + { + params: { memberId }, + withCredentials: true, + } + ); + return response.data; + } catch (error) { + if (error instanceof AxiosError) { + console.error('이미지 목록 업로드 실패:', error.response?.data?.message || '알 수 없는 오류'); + } else { + console.error('알 수 없는 오류가 발생했습니다.'); + } + throw error; + } +};