Skip to content

Commit

Permalink
#244 feat: News 엔드포인트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
pillow12360 committed Jan 5, 2025
1 parent 0d8df52 commit 28360d1
Showing 1 changed file with 58 additions and 17 deletions.
75 changes: 58 additions & 17 deletions frontend/src/config/apiConfig.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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[]) => {
Expand All @@ -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;
},
},
Expand Down Expand Up @@ -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;
},
},
Expand All @@ -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;
},
},
Expand Down Expand Up @@ -189,37 +231,39 @@ 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`,
listWithPage: (page: number, size: number) =>
`${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({
Expand All @@ -231,12 +275,9 @@ export const apiEndpoints = {
departmentId: 1,
}),
);

// boardFiles 추가
files.forEach((file) => {
formData.append('boardFiles', file);
});

return formData;
},
},
Expand Down

0 comments on commit 28360d1

Please sign in to comment.