From dc2040e077592a05c6355d2b99ea6e94fff51d78 Mon Sep 17 00:00:00 2001 From: Wibaek Park Date: Fri, 14 Feb 2025 12:01:58 +0900 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20=EC=A7=80=EC=9B=90=EC=84=9C=20uri?= =?UTF-8?q?=20=EB=B3=B5=EC=88=98=ED=98=95=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/application.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/application.ts b/src/services/application.ts index 27a932a3..38d4a80c 100644 --- a/src/services/application.ts +++ b/src/services/application.ts @@ -14,19 +14,19 @@ import { // DEPRECATED export const postApplicationScoreApi = ( applicationScoreRequest: ApplicationScoreRequest, -): Promise> => axiosInstance.post("/application/score", applicationScoreRequest); +): Promise> => axiosInstance.post("/applications/score", applicationScoreRequest); // DEPRECATED export const postApplicationUniversityApi = ( applicationUniversityRequest: ApplicationUniversityRequest, -): Promise> => axiosInstance.post("/application/university", applicationUniversityRequest); +): Promise> => axiosInstance.post("/applications/university", applicationUniversityRequest); export const postApplicationApi = ( request: SubmitApplicationRequest, -): Promise> => axiosInstance.post("/application", request); +): Promise> => axiosInstance.post("/applications", request); export const getApplicationListApi = (): Promise> => - axiosInstance.get("/application"); + axiosInstance.get("/applications"); export const getMyApplicationStatusApi = (): Promise> => - axiosInstance.get("/application/status"); + axiosInstance.get("/applications/status"); From 37f184b51331352e5273d794e6c90344a25ed2be Mon Sep 17 00:00:00 2001 From: Wibaek Park Date: Fri, 14 Feb 2025 12:22:18 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20u?= =?UTF-8?q?ri=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[boardCode]/[postId]/KebabMenu.tsx | 2 +- .../community/[boardCode]/[postId]/Post.tsx | 4 +-- .../[postId]/modify/PostModifyForm.tsx | 2 +- .../[boardCode]/[postId]/modify/page.tsx | 2 +- .../community/[boardCode]/[postId]/page.tsx | 2 +- .../community/[boardCode]/create/PostForm.tsx | 3 ++- src/services/community.ts | 27 ++++++++----------- src/types/community.ts | 1 + 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/app/community/[boardCode]/[postId]/KebabMenu.tsx b/src/app/community/[boardCode]/[postId]/KebabMenu.tsx index 80926dbb..19f151c9 100644 --- a/src/app/community/[boardCode]/[postId]/KebabMenu.tsx +++ b/src/app/community/[boardCode]/[postId]/KebabMenu.tsx @@ -19,7 +19,7 @@ const KebabMenu = ({ boardCode, postId }: KebabMenuProps) => { const toggleDeletePost = () => { if (!window.confirm("정말 삭제하시겠습니까?")) return; - deletePostApi(boardCode, postId) + deletePostApi(postId) .then(() => { alert("게시글이 삭제되었습니다."); router.push(`/community/${boardCode}`); diff --git a/src/app/community/[boardCode]/[postId]/Post.tsx b/src/app/community/[boardCode]/[postId]/Post.tsx index 33421a8c..bc78ebe8 100644 --- a/src/app/community/[boardCode]/[postId]/Post.tsx +++ b/src/app/community/[boardCode]/[postId]/Post.tsx @@ -41,13 +41,13 @@ const Post = ({ post, boardCode, postId }: PostProps) => { if (isLiked) { setLikeCount((prev) => prev - 1); setIsLiked(false); - const res = await unlikePostApi(boardCode, postId); + const res = await unlikePostApi(postId); setLikeCount(res.data.likeCount); setIsLiked(res.data.isLiked); } else { setLikeCount((prev) => prev + 1); setIsLiked(true); - const res = await likePostApi(boardCode, postId); + const res = await likePostApi(postId); setLikeCount(res.data.likeCount); setIsLiked(res.data.isLiked); } diff --git a/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx b/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx index f0751a78..218b431d 100644 --- a/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx +++ b/src/app/community/[boardCode]/[postId]/modify/PostModifyForm.tsx @@ -60,7 +60,7 @@ const PostModifyForm = ({ const submitPost = async () => { try { - await updatePostApi(boardCode, postId, { + await updatePostApi(postId, { postUpdateRequest: { postCategory: defaultPostCategory, title, diff --git a/src/app/community/[boardCode]/[postId]/modify/page.tsx b/src/app/community/[boardCode]/[postId]/modify/page.tsx index 15205bd7..71e89a01 100644 --- a/src/app/community/[boardCode]/[postId]/modify/page.tsx +++ b/src/app/community/[boardCode]/[postId]/modify/page.tsx @@ -18,7 +18,7 @@ const PostModifyPage = ({ params }: { params: { boardCode: string; postId: strin useEffect(() => { const fetchPost = async () => { try { - const res = await getPostDetailApi(boardCode, Number(postId)); + const res = await getPostDetailApi(Number(postId)); setPost(res.data); } catch (err) { // 에러 처리 diff --git a/src/app/community/[boardCode]/[postId]/page.tsx b/src/app/community/[boardCode]/[postId]/page.tsx index 6cf6aaa8..9d23ca63 100644 --- a/src/app/community/[boardCode]/[postId]/page.tsx +++ b/src/app/community/[boardCode]/[postId]/page.tsx @@ -25,7 +25,7 @@ const PostPage = ({ params }: { params: { boardCode: string; postId: string } }) useEffect(() => { const fetchPosts = async () => { - await getPostDetailApi(boardCode, postId) + await getPostDetailApi(postId) .then((res) => { setPost(res.data); }) diff --git a/src/app/community/[boardCode]/create/PostForm.tsx b/src/app/community/[boardCode]/create/PostForm.tsx index 90efd285..1d56123e 100644 --- a/src/app/community/[boardCode]/create/PostForm.tsx +++ b/src/app/community/[boardCode]/create/PostForm.tsx @@ -44,8 +44,9 @@ const PostForm = ({ boardCode }: PostFormProps) => { const submitPost = async () => { try { - const res = await createPostApi(boardCode, { + const res = await createPostApi({ postCreateRequest: { + boardCode: boardCode, postCategory: isQuestion ? "질문" : "자유", title: titleRef.current?.querySelector("textarea")?.value || "", content, diff --git a/src/services/community.ts b/src/services/community.ts index e5d825cd..3b24e919 100644 --- a/src/services/community.ts +++ b/src/services/community.ts @@ -14,19 +14,15 @@ import { } from "@/types/community"; export const getPostListApi = (boardCode: string, category: string | null = null): Promise> => - axiosInstance.get(`/communities/${boardCode}`, { + axiosInstance.get(`/boards/${boardCode}`, { params: { category, }, }); -export const getPostDetailApi = (boardCode: string, postId: number): Promise> => - axiosInstance.get(`/communities/${boardCode}/posts/${postId}`); +export const getPostDetailApi = (postId: number): Promise> => axiosInstance.get(`/posts/${postId}`); -export const createPostApi = ( - boardCode: string, - postCreateRequest: PostCreateRequest, -): Promise> => { +export const createPostApi = (postCreateRequest: PostCreateRequest): Promise> => { const convertedRequest: FormData = new FormData(); convertedRequest.append( "postCreateRequest", @@ -36,13 +32,12 @@ export const createPostApi = ( convertedRequest.append("file", file); }); - return axiosInstance.post(`/communities/${boardCode}/posts`, convertedRequest, { + return axiosInstance.post(`/posts`, convertedRequest, { headers: { "Content-Type": "multipart/form-data" }, }); }; export const updatePostApi = ( - boardCode: string, postId: number, postUpdateRequest: PostUpdateRequest, ): Promise> => { @@ -54,19 +49,19 @@ export const updatePostApi = ( postUpdateRequest.file.forEach((file) => { convertedRequest.append("file", file); }); - return axiosInstance.patch(`/communities/${boardCode}/posts/${postId}`, convertedRequest, { + return axiosInstance.patch(`/posts/${postId}`, convertedRequest, { headers: { "Content-Type": "multipart/form-data" }, }); }; -export const deletePostApi = (boardCode: string, postId: number): Promise> => - axiosInstance.delete(`/communities/${boardCode}/posts/${postId}`); +export const deletePostApi = (postId: number): Promise> => + axiosInstance.delete(`/posts/${postId}`); -export const likePostApi = (boardCode, postId: number): Promise> => - axiosInstance.post(`/communities/${boardCode}/posts/${postId}/like`); +export const likePostApi = (postId: number): Promise> => + axiosInstance.post(`/posts/${postId}/like`); -export const unlikePostApi = (boardCode, postId: number): Promise> => - axiosInstance.delete(`/communities/${boardCode}/posts/${postId}/like`); +export const unlikePostApi = (postId: number): Promise> => + axiosInstance.delete(`/posts/${postId}/like`); export const createCommentApi = ( postId: number, diff --git a/src/types/community.ts b/src/types/community.ts index 09ac5b9e..704df2ae 100644 --- a/src/types/community.ts +++ b/src/types/community.ts @@ -57,6 +57,7 @@ export interface ListPost { export interface PostCreateRequest { postCreateRequest: { + boardCode: string; postCategory: string; title: string; content: string; From e94d6bc903bc8b85067c5f8afead59dd0cf441f9 Mon Sep 17 00:00:00 2001 From: Wibaek Park Date: Fri, 14 Feb 2025 13:59:01 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=EB=8C=93=EA=B8=80=20uri=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/community/[boardCode]/[postId]/CommentWrite.tsx | 3 ++- src/services/community.ts | 5 ++--- src/types/community.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/community/[boardCode]/[postId]/CommentWrite.tsx b/src/app/community/[boardCode]/[postId]/CommentWrite.tsx index c3691c49..527f37b9 100644 --- a/src/app/community/[boardCode]/[postId]/CommentWrite.tsx +++ b/src/app/community/[boardCode]/[postId]/CommentWrite.tsx @@ -18,7 +18,8 @@ const CommentWrite = ({ postId, refresh, curSelectedComment, setCurSelectedComme const submitComment = async () => { try { - await createCommentApi(postId, { + await createCommentApi({ + postId: postId, content: contentRef.current?.value || "", parentId: curSelectedComment, }); diff --git a/src/services/community.ts b/src/services/community.ts index 3b24e919..d0312a23 100644 --- a/src/services/community.ts +++ b/src/services/community.ts @@ -64,11 +64,10 @@ export const unlikePostApi = (postId: number): Promise> => axiosInstance.post(`/posts/${postId}/comments`, commentCreateRequest); +): Promise> => axiosInstance.post(`/comments`, commentCreateRequest); export const deleteCommentApi = (postId: number, commentId: number): Promise> => - axiosInstance.delete(`/posts/${postId}/comments/${commentId}`); + axiosInstance.delete(`/comments/${commentId}`); // export const updateCommentApi diff --git a/src/types/community.ts b/src/types/community.ts index 704df2ae..f0579dba 100644 --- a/src/types/community.ts +++ b/src/types/community.ts @@ -76,6 +76,7 @@ export interface PostUpdateRequest { } export interface CommentCreateRequest { + postId: number; content: string; parentId: number | null; } From 2b0590cbe96e2a1ac825894e25fb26dea9dbf6ec Mon Sep 17 00:00:00 2001 From: Wibaek Park Date: Fri, 14 Feb 2025 15:22:30 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=EC=84=B1=EC=A0=81=20api=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/score/submit/gpa/GpaSubmitForm.tsx | 6 +----- .../score/submit/language-test/LanguageTestSubmitForm.tsx | 6 +----- src/services/score.ts | 8 ++++---- src/types/score.ts | 4 ++-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/app/score/submit/gpa/GpaSubmitForm.tsx b/src/app/score/submit/gpa/GpaSubmitForm.tsx index 120bcbc4..3a28657a 100644 --- a/src/app/score/submit/gpa/GpaSubmitForm.tsx +++ b/src/app/score/submit/gpa/GpaSubmitForm.tsx @@ -42,15 +42,11 @@ const GpaSubmitForm = () => { async function postData() { try { - const fileUploadRes = await uploadGpaFileApi(file as File); - const fileUrl = fileUploadRes.data.fileUrl; - - // API 호출 const res = await postGpaScoreApi({ gpa: Number(gpa), gpaCriteria: gpaCriteria as number, issueDate: "2025-01-01", - gpaReportUrl: fileUrl, + file: file as File, }); router.push("/score"); diff --git a/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx b/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx index 6ab7b371..fb6f489b 100644 --- a/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx +++ b/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx @@ -69,15 +69,11 @@ const LanguageTestSubmitForm = () => { async function postData() { try { - const fileUploadRes = await uploadLanguageTestFileApi(file as File); - const fileUrl = fileUploadRes.data.fileUrl; - - // API 호출 const res = await postLanguageTestScoreApi({ languageTestType: testType, languageTestScore: score, issueDate: "2025-01-01", - languageTestReportUrl: fileUrl, + file: file as File, }); router.push("/score"); diff --git a/src/services/score.ts b/src/services/score.ts index 6984ae67..51dfd0c0 100644 --- a/src/services/score.ts +++ b/src/services/score.ts @@ -10,12 +10,12 @@ import { } from "@/types/score"; export const postGpaScoreApi = (request: SubmitGpaScoreRequest): Promise> => - axiosInstance.post("/score/gpa", request); + axiosInstance.post("/scores/gpas", request, { headers: { "Content-Type": "multipart/form-data" } }); export const postLanguageTestScoreApi = (request: SubmitLanguageTestScoreRequest): Promise> => - axiosInstance.post("/score/languageTest", request); + axiosInstance.post("/scores/language-tests", request, { headers: { "Content-Type": "multipart/form-data" } }); -export const getMyGpaScoreApi = (): Promise> => axiosInstance.get("/score/gpa"); +export const getMyGpaScoreApi = (): Promise> => axiosInstance.get("/scores/gpas"); export const getMyLanguageTestScoreApi = (): Promise> => - axiosInstance.get("/score/languageTest"); + axiosInstance.get("/scores/language-tests"); diff --git a/src/types/score.ts b/src/types/score.ts index 8d8b2927..2b72cb49 100644 --- a/src/types/score.ts +++ b/src/types/score.ts @@ -2,14 +2,14 @@ export interface SubmitGpaScoreRequest { gpa: number; gpaCriteria: number; issueDate: string; // yyyy-MM-dd - gpaReportUrl: string; + file: Blob; } export interface SubmitLanguageTestScoreRequest { languageTestType: string; languageTestScore: string; issueDate: string; // yyyy-MM-dd - languageTestReportUrl: string; + file: Blob; } export interface GpaScore { From fc4909f20eababc5d946a2fb949d22734c94ba5c Mon Sep 17 00:00:00 2001 From: Wibaek Park Date: Fri, 14 Feb 2025 15:30:16 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20validateLanguageScore()=20?= =?UTF-8?q?=EC=96=B8=EC=96=B4=20=EC=84=B1=EC=A0=81=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EA=B0=92=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/score/submit/gpa/GpaSubmitForm.tsx | 1 - .../language-test/LanguageTestSubmitForm.tsx | 36 ++++--------------- src/utils/scoreUtils.ts | 31 ++++++++++++++++ 3 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 src/utils/scoreUtils.ts diff --git a/src/app/score/submit/gpa/GpaSubmitForm.tsx b/src/app/score/submit/gpa/GpaSubmitForm.tsx index 3a28657a..e0a3a972 100644 --- a/src/app/score/submit/gpa/GpaSubmitForm.tsx +++ b/src/app/score/submit/gpa/GpaSubmitForm.tsx @@ -6,7 +6,6 @@ import { useRef, useState } from "react"; import clsx from "clsx"; -import { uploadGpaFileApi } from "@/services/file"; import { postGpaScoreApi } from "@/services/score"; import BlockBtn from "@/components/button/BlockBtn"; diff --git a/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx b/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx index fb6f489b..b08f97ff 100644 --- a/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx +++ b/src/app/score/submit/language-test/LanguageTestSubmitForm.tsx @@ -6,8 +6,8 @@ import { useRef, useState } from "react"; import clsx from "clsx"; -import { uploadLanguageTestFileApi } from "@/services/file"; import { postLanguageTestScoreApi } from "@/services/score"; +import { validateLanguageScore } from "@/utils/scoreUtils"; import BlockBtn from "@/components/button/BlockBtn"; import RoundBtn from "@/components/button/RoundBtn"; @@ -36,35 +36,11 @@ const LanguageTestSubmitForm = () => { } // 점수 유효성 검사 - if (testType === "TOEIC") { - if (!(Number(score) >= 0 && Number(score) <= 990)) { - alert("TOEIC 점수는 0 ~ 990 사이여야 합니다."); - return; - } - } - if (testType === "TOEFL IBT") { - if (!(Number(score) >= 0 && Number(score) <= 120)) { - alert("TOEFL IBT 점수는 0 ~ 120 사이여야 합니다."); - return; - } - } - if (testType === "TOEFL ITP") { - if (!(Number(score) >= 310 && Number(score) <= 677)) { - alert("TOEFL ITP 점수는 310 ~ 677 사이여야 합니다."); - return; - } - } - if (testType === "IELTS") { - if (!(Number(score) >= 0 && Number(score) <= 9)) { - alert("IELTS 점수는 0 ~ 9 사이여야 합니다."); - return; - } - } - if (testType === "JLPT") { - if (!(Number(score) >= 0 && Number(score) <= 5)) { - alert("JLPT 점수는 0 ~ 5 사이여야 합니다."); - return; - } + try { + validateLanguageScore(testType, score); + } catch (err: any) { + alert(err.message); + return; } async function postData() { diff --git a/src/utils/scoreUtils.ts b/src/utils/scoreUtils.ts new file mode 100644 index 00000000..16b5b2e9 --- /dev/null +++ b/src/utils/scoreUtils.ts @@ -0,0 +1,31 @@ +export const validateLanguageScore = (testType: string, score: string) => { + const numScore = Number(score); + + if (testType === "TOEIC") { + if (!(numScore >= 0 && numScore <= 990)) { + alert("TOEIC 점수는 0 ~ 990 사이여야 합니다."); + throw new Error("TOEIC 점수는 0 ~ 990 사이여야 합니다."); + } + } + if (testType === "TOEFL IBT") { + if (!(numScore >= 0 && numScore <= 120)) { + alert("TOEFL IBT 점수는 0 ~ 120 사이여야 합니다."); + throw new Error("TOEFL IBT 점수는 0 ~ 120 사이여야 합니다."); + } + } + if (testType === "TOEFL ITP") { + if (!(numScore >= 310 && numScore <= 677)) { + throw new Error("TOEFL ITP 점수는 310 ~ 677 사이여야 합니다."); + } + } + if (testType === "IELTS") { + if (!(numScore >= 0 && numScore <= 9)) { + throw new Error("IELTS 점수는 0 ~ 9 사이여야 합니다."); + } + } + if (testType === "JLPT") { + if (!(numScore >= 1 && numScore <= 5)) { + throw new Error("JLPT 등급은 1 ~ 5 사이여야 합니다."); + } + } +};