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/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/app/score/submit/gpa/GpaSubmitForm.tsx b/src/app/score/submit/gpa/GpaSubmitForm.tsx index 120bcbc4..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"; @@ -42,15 +41,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..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,48 +36,20 @@ 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() { 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/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"); diff --git a/src/services/community.ts b/src/services/community.ts index e5d825cd..d0312a23 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,26 +49,25 @@ 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, commentCreateRequest: CommentCreateRequest, -): 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/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/community.ts b/src/types/community.ts index 09ac5b9e..f0579dba 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; @@ -75,6 +76,7 @@ export interface PostUpdateRequest { } export interface CommentCreateRequest { + postId: number; content: string; parentId: number | null; } 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 { 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 사이여야 합니다."); + } + } +};