Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/community/[boardCode]/[postId]/CommentWrite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/community/[boardCode]/[postId]/KebabMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 2 additions & 2 deletions src/app/community/[boardCode]/[postId]/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const PostModifyForm = ({

const submitPost = async () => {
try {
await updatePostApi(boardCode, postId, {
await updatePostApi(postId, {
postUpdateRequest: {
postCategory: defaultPostCategory,
title,
Expand Down
2 changes: 1 addition & 1 deletion src/app/community/[boardCode]/[postId]/modify/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
// 에러 처리
Expand Down
2 changes: 1 addition & 1 deletion src/app/community/[boardCode]/[postId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down
3 changes: 2 additions & 1 deletion src/app/community/[boardCode]/create/PostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions src/app/score/submit/gpa/GpaSubmitForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down
42 changes: 7 additions & 35 deletions src/app/score/submit/language-test/LanguageTestSubmitForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions src/services/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import {
// DEPRECATED
export const postApplicationScoreApi = (
applicationScoreRequest: ApplicationScoreRequest,
): Promise<AxiosResponse<null>> => axiosInstance.post("/application/score", applicationScoreRequest);
): Promise<AxiosResponse<null>> => axiosInstance.post("/applications/score", applicationScoreRequest);

// DEPRECATED
export const postApplicationUniversityApi = (
applicationUniversityRequest: ApplicationUniversityRequest,
): Promise<AxiosResponse<null>> => axiosInstance.post("/application/university", applicationUniversityRequest);
): Promise<AxiosResponse<null>> => axiosInstance.post("/applications/university", applicationUniversityRequest);

export const postApplicationApi = (
request: SubmitApplicationRequest,
): Promise<AxiosResponse<SubmitApplicationResponse>> => axiosInstance.post("/application", request);
): Promise<AxiosResponse<SubmitApplicationResponse>> => axiosInstance.post("/applications", request);

export const getApplicationListApi = (): Promise<AxiosResponse<ApplicationListResponse>> =>
axiosInstance.get("/application");
axiosInstance.get("/applications");

export const getMyApplicationStatusApi = (): Promise<AxiosResponse<ApplicationStatusResponse>> =>
axiosInstance.get("/application/status");
axiosInstance.get("/applications/status");
32 changes: 13 additions & 19 deletions src/services/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ import {
} from "@/types/community";

export const getPostListApi = (boardCode: string, category: string | null = null): Promise<AxiosResponse<ListPost[]>> =>
axiosInstance.get(`/communities/${boardCode}`, {
axiosInstance.get(`/boards/${boardCode}`, {
params: {
category,
},
});

export const getPostDetailApi = (boardCode: string, postId: number): Promise<AxiosResponse<Post>> =>
axiosInstance.get(`/communities/${boardCode}/posts/${postId}`);
export const getPostDetailApi = (postId: number): Promise<AxiosResponse<Post>> => axiosInstance.get(`/posts/${postId}`);

export const createPostApi = (
boardCode: string,
postCreateRequest: PostCreateRequest,
): Promise<AxiosResponse<PostIdResponse>> => {
export const createPostApi = (postCreateRequest: PostCreateRequest): Promise<AxiosResponse<PostIdResponse>> => {
const convertedRequest: FormData = new FormData();
convertedRequest.append(
"postCreateRequest",
Expand All @@ -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<AxiosResponse<PostIdResponse>> => {
Expand All @@ -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<AxiosResponse<PostIdResponse>> =>
axiosInstance.delete(`/communities/${boardCode}/posts/${postId}`);
export const deletePostApi = (postId: number): Promise<AxiosResponse<PostIdResponse>> =>
axiosInstance.delete(`/posts/${postId}`);

export const likePostApi = (boardCode, postId: number): Promise<AxiosResponse<PostLikeResponse>> =>
axiosInstance.post(`/communities/${boardCode}/posts/${postId}/like`);
export const likePostApi = (postId: number): Promise<AxiosResponse<PostLikeResponse>> =>
axiosInstance.post(`/posts/${postId}/like`);

export const unlikePostApi = (boardCode, postId: number): Promise<AxiosResponse<PostLikeResponse>> =>
axiosInstance.delete(`/communities/${boardCode}/posts/${postId}/like`);
export const unlikePostApi = (postId: number): Promise<AxiosResponse<PostLikeResponse>> =>
axiosInstance.delete(`/posts/${postId}/like`);

export const createCommentApi = (
postId: number,
commentCreateRequest: CommentCreateRequest,
): Promise<AxiosResponse<CommentIdResponse>> => axiosInstance.post(`/posts/${postId}/comments`, commentCreateRequest);
): Promise<AxiosResponse<CommentIdResponse>> => axiosInstance.post(`/comments`, commentCreateRequest);

export const deleteCommentApi = (postId: number, commentId: number): Promise<AxiosResponse<CommentIdResponse>> =>
axiosInstance.delete(`/posts/${postId}/comments/${commentId}`);
axiosInstance.delete(`/comments/${commentId}`);

// export const updateCommentApi
8 changes: 4 additions & 4 deletions src/services/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
} from "@/types/score";

export const postGpaScoreApi = (request: SubmitGpaScoreRequest): Promise<AxiosResponse<null>> =>
axiosInstance.post("/score/gpa", request);
axiosInstance.post("/scores/gpas", request, { headers: { "Content-Type": "multipart/form-data" } });

export const postLanguageTestScoreApi = (request: SubmitLanguageTestScoreRequest): Promise<AxiosResponse<null>> =>
axiosInstance.post("/score/languageTest", request);
axiosInstance.post("/scores/language-tests", request, { headers: { "Content-Type": "multipart/form-data" } });

export const getMyGpaScoreApi = (): Promise<AxiosResponse<MyGpaScoreResponse>> => axiosInstance.get("/score/gpa");
export const getMyGpaScoreApi = (): Promise<AxiosResponse<MyGpaScoreResponse>> => axiosInstance.get("/scores/gpas");

export const getMyLanguageTestScoreApi = (): Promise<AxiosResponse<MyLanguageTestScoreResponse>> =>
axiosInstance.get("/score/languageTest");
axiosInstance.get("/scores/language-tests");
2 changes: 2 additions & 0 deletions src/types/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface ListPost {

export interface PostCreateRequest {
postCreateRequest: {
boardCode: string;
postCategory: string;
title: string;
content: string;
Expand All @@ -75,6 +76,7 @@ export interface PostUpdateRequest {
}

export interface CommentCreateRequest {
postId: number;
content: string;
parentId: number | null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions src/utils/scoreUtils.ts
Original file line number Diff line number Diff line change
@@ -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 사이여야 합니다.");
}
}
};