diff --git a/frontend/src/config/apiConfig.ts b/frontend/src/config/apiConfig.ts index 3e0d69a1..18c5d8c8 100644 --- a/frontend/src/config/apiConfig.ts +++ b/frontend/src/config/apiConfig.ts @@ -1,5 +1,13 @@ const API_URL = process.env.REACT_APP_API_URL; +export interface NewsReqDto { + title: string; + content: string; + link: string; + image: string; + createDate: string; +} + export interface BoardReqDto { title: string; content: string; @@ -52,6 +60,51 @@ export interface SeminarDto { } export const apiEndpoints = { + news: { + list: `${API_URL}/api/news`, + listWithPage: (page: number, size: number) => { + const params = new URLSearchParams({ + page: page.toString(), + size: size.toString(), + }); + return `${API_URL}/api/news?${params.toString()}`; + }, + create: { + url: `${API_URL}/api/news`, + getFormData: (newsReqDto: NewsReqDto, imageFile?: File | null) => { + const formData = new FormData(); + formData.append( + 'newsReqDto', + new Blob([JSON.stringify(newsReqDto)], { + type: 'application/json', + }), + ); + if (imageFile) { + formData.append('news_image', imageFile); + } + return formData; + }, + }, + get: (newsId: string | number) => `${API_URL}/api/news/${newsId}`, + update: { + url: (newsId: string | number) => `${API_URL}/api/news/${newsId}`, + getFormData: (newsReqDto: NewsReqDto, imageFile?: File | null) => { + const formData = new FormData(); + formData.append( + 'newsReqDto', + new Blob([JSON.stringify(newsReqDto)], { + type: 'application/json', + }), + ); + if (imageFile) { + formData.append('news_image', imageFile); + } + return formData; + }, + }, + delete: (newsId: string | number) => `${API_URL}/api/news/${newsId}`, + }, + thesis: { list: `${API_URL}/api/thesis`, listWithPage: (page: number, size: number, sort?: string[]) => { @@ -68,20 +121,15 @@ export const apiEndpoints = { url: `${API_URL}/api/thesis`, getFormData: (thesisReqDto: ThesisReqDto, imageFile?: File | null) => { const formData = new FormData(); - - // thesisReqDto를 JSON 문자열로 변환하여 추가 formData.append( 'thesisReqDto', new Blob([JSON.stringify(thesisReqDto)], { type: 'application/json', }), ); - - // thesis_image 추가 if (imageFile) { formData.append('thesis_image', imageFile); } - return formData; }, }, @@ -124,18 +172,15 @@ export const apiEndpoints = { imageFile?: File | null, ) => { const formData = new FormData(); - formData.append( 'professorReqDto', new Blob([JSON.stringify(professorReqDto)], { type: 'application/json', }), ); - if (imageFile) { formData.append('profileImage', imageFile); } - return formData; }, }, @@ -146,18 +191,15 @@ export const apiEndpoints = { imageFile?: File | null, ) => { const formData = new FormData(); - formData.append( 'professorReqDto', new Blob([JSON.stringify(professorReqDto)], { type: 'application/json', }), ); - if (imageFile) { formData.append('profile_image', imageFile); } - return formData; }, }, @@ -189,25 +231,30 @@ export const apiEndpoints = { detail: (professorId: number) => `${API_URL}/api/professor/${professorId}`, }, + admin: { login: `${API_URL}/api/admin/login`, signOut: `${API_URL}/api/admin/signOut`, register: `${API_URL}/api/admin/join`, }, + user: { login: `${API_URL}/api/user/login`, signOut: `${API_URL}/logout`, register: `${API_URL}/register`, }, + department: { get: (id: string) => `${API_URL}/api/departments/${id}`, update: (id: string) => `${API_URL}/api/departments/${id}`, delete: (id: string) => `${API_URL}/api/departments/${id}`, create: `${API_URL}/api/departments`, }, + main: { get: `${API_URL}/api/`, }, + board: { base: `${API_URL}/api/board`, download: `${API_URL}/api/board/download`, @@ -215,11 +262,8 @@ export const apiEndpoints = { `${API_URL}/api/board?page=${page}&size=${size}`, create: { url: `${API_URL}/api/board`, - // API 명세에 맞게 요청 형식 지정 getFormData: (boardReqDto: BoardReqDto, files: File[]) => { const formData = new FormData(); - - // boardReqDto를 JSON 문자열로 변환하여 추가 formData.append( 'boardReqDto', JSON.stringify({ @@ -231,12 +275,9 @@ export const apiEndpoints = { departmentId: 1, }), ); - - // boardFiles 추가 files.forEach((file) => { formData.append('boardFiles', file); }); - return formData; }, },