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; + } +};