Skip to content

Commit 06240f5

Browse files
authored
Merge pull request #49 from FE9-2/feat/api-route
Feat: API route 파일들 추가
2 parents 2951fe7 + 847738d commit 06240f5

File tree

25 files changed

+1302
-5
lines changed

25 files changed

+1302
-5
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { AxiosError } from "axios";
2+
import { cookies } from "next/headers";
3+
import { NextRequest, NextResponse } from "next/server";
4+
import apiClient from "@/lib/apiClient";
5+
6+
export async function POST(req: NextRequest) {
7+
try {
8+
const accessToken = cookies().get("accessToken")?.value;
9+
10+
if (!accessToken) {
11+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
12+
}
13+
14+
const formData = await req.formData();
15+
const file = formData.get("file");
16+
17+
if (!file) {
18+
return NextResponse.json({ message: "파일이 필요합니다." }, { status: 400 });
19+
}
20+
21+
// FormData 생성 및 파일 추가
22+
const uploadFormData = new FormData();
23+
uploadFormData.append("file", file);
24+
25+
const response = await apiClient.post("/images/upload", uploadFormData, {
26+
headers: {
27+
Authorization: `Bearer ${accessToken}`,
28+
"Content-Type": "multipart/form-data",
29+
},
30+
});
31+
32+
return NextResponse.json(response.data);
33+
} catch (error: unknown) {
34+
if (error instanceof AxiosError) {
35+
console.error("POST /api/images/upload error:", error);
36+
if (error.response) {
37+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
38+
}
39+
}
40+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { AxiosError } from "axios";
2+
import { cookies } from "next/headers";
3+
import { NextRequest, NextResponse } from "next/server";
4+
import apiClient from "@/lib/apiClient";
5+
6+
export async function GET(req: NextRequest, { params }: { params: { resumeId: string } }) {
7+
try {
8+
const accessToken = cookies().get("accessToken")?.value;
9+
10+
if (!accessToken) {
11+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
12+
}
13+
14+
const response = await apiClient.get(`/${params.resumeId}/download`, {
15+
headers: {
16+
Authorization: `Bearer ${accessToken}`,
17+
},
18+
responseType: "arraybuffer",
19+
});
20+
21+
// Content-Disposition 헤더에서 파일명 추출
22+
const contentDisposition = response.headers["content-disposition"];
23+
const filenameMatch = contentDisposition?.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
24+
const filename = filenameMatch ? filenameMatch[1].replace(/['"]/g, "") : "resume.pdf";
25+
26+
// 파일 다운로드를 위한 응답 헤더 설정
27+
return new NextResponse(response.data, {
28+
headers: {
29+
"Content-Type": response.headers["content-type"] || "application/pdf",
30+
"Content-Disposition": `attachment; filename="${filename}"`,
31+
},
32+
});
33+
} catch (error: unknown) {
34+
if (error instanceof AxiosError) {
35+
console.error(`GET /api/resume/${params.resumeId}/download error:`, error);
36+
if (error.response) {
37+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
38+
}
39+
}
40+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { AxiosError } from "axios";
2+
import { cookies } from "next/headers";
3+
import { NextRequest, NextResponse } from "next/server";
4+
import apiClient from "@/lib/apiClient";
5+
6+
export async function POST(req: NextRequest) {
7+
try {
8+
const accessToken = cookies().get("accessToken")?.value;
9+
10+
if (!accessToken) {
11+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
12+
}
13+
14+
const formData = await req.formData();
15+
const file = formData.get("file");
16+
17+
if (!file) {
18+
return NextResponse.json({ message: "이력서 파일이 필요합니다." }, { status: 400 });
19+
}
20+
21+
// FormData 생성 및 파일 추가
22+
const uploadFormData = new FormData();
23+
uploadFormData.append("file", file);
24+
25+
const response = await apiClient.post("/resume/upload", uploadFormData, {
26+
headers: {
27+
Authorization: `Bearer ${accessToken}`,
28+
"Content-Type": "multipart/form-data",
29+
},
30+
});
31+
32+
return NextResponse.json(response.data);
33+
} catch (error: unknown) {
34+
if (error instanceof AxiosError) {
35+
console.error("POST /api/resume/upload error:", error);
36+
if (error.response) {
37+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
38+
}
39+
}
40+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
41+
}
42+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { AxiosError } from "axios";
2+
import { cookies } from "next/headers";
3+
import { NextRequest, NextResponse } from "next/server";
4+
import apiClient from "@/lib/apiClient";
5+
6+
// 지원서 상세 조회
7+
export async function GET(req: NextRequest, { params }: { params: { applicationId: string } }) {
8+
try {
9+
const accessToken = cookies().get("accessToken")?.value;
10+
11+
if (!accessToken) {
12+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
13+
}
14+
15+
const response = await apiClient.get(`/applications/${params.applicationId}`, {
16+
headers: {
17+
Authorization: `Bearer ${accessToken}`,
18+
},
19+
});
20+
21+
return NextResponse.json(response.data);
22+
} catch (error: unknown) {
23+
if (error instanceof AxiosError) {
24+
console.error(`GET /api/applications/${params.applicationId} error:`, error);
25+
if (error.response) {
26+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
27+
}
28+
}
29+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
30+
}
31+
}
32+
33+
// 지원서 상태 수정
34+
export async function PATCH(req: NextRequest, { params }: { params: { applicationId: string } }) {
35+
try {
36+
const accessToken = cookies().get("accessToken")?.value;
37+
38+
if (!accessToken) {
39+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
40+
}
41+
42+
const body = await req.json();
43+
44+
const response = await apiClient.patch(`/applications/${params.applicationId}`, body, {
45+
headers: {
46+
Authorization: `Bearer ${accessToken}`,
47+
},
48+
});
49+
50+
return NextResponse.json(response.data);
51+
} catch (error: unknown) {
52+
if (error instanceof AxiosError) {
53+
console.error(`PATCH /api/applications/${params.applicationId} error:`, error);
54+
if (error.response) {
55+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
56+
}
57+
}
58+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
59+
}
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { AxiosError } from "axios";
2+
import { cookies } from "next/headers";
3+
import { NextRequest, NextResponse } from "next/server";
4+
import apiClient from "@/lib/apiClient";
5+
6+
// 댓글 수정
7+
export async function PATCH(req: NextRequest, { params }: { params: { commentId: string } }) {
8+
try {
9+
const accessToken = cookies().get("accessToken")?.value;
10+
11+
if (!accessToken) {
12+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
13+
}
14+
15+
const body = await req.json();
16+
17+
const response = await apiClient.patch(`/comments/${params.commentId}`, body, {
18+
headers: {
19+
Authorization: `Bearer ${accessToken}`,
20+
},
21+
});
22+
23+
return NextResponse.json(response.data);
24+
} catch (error: unknown) {
25+
if (error instanceof AxiosError) {
26+
console.error(`PATCH /api/comments/${params.commentId} error:`, error);
27+
if (error.response) {
28+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
29+
}
30+
}
31+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
32+
}
33+
}
34+
35+
// 댓글 삭제
36+
export async function DELETE(req: NextRequest, { params }: { params: { commentId: string } }) {
37+
try {
38+
const accessToken = cookies().get("accessToken")?.value;
39+
40+
if (!accessToken) {
41+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
42+
}
43+
44+
const response = await apiClient.delete(`/comments/${params.commentId}`, {
45+
headers: {
46+
Authorization: `Bearer ${accessToken}`,
47+
},
48+
});
49+
50+
return NextResponse.json(response.data);
51+
} catch (error: unknown) {
52+
if (error instanceof AxiosError) {
53+
console.error(`DELETE /api/comments/${params.commentId} error:`, error);
54+
if (error.response) {
55+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
56+
}
57+
}
58+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
59+
}
60+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { AxiosError } from "axios";
2+
import { cookies } from "next/headers";
3+
import { NextRequest, NextResponse } from "next/server";
4+
import apiClient from "@/lib/apiClient";
5+
6+
// 회원의 내 지원 내역 조회
7+
export async function GET(req: NextRequest, { params }: { params: { formId: string } }) {
8+
try {
9+
const accessToken = cookies().get("accessToken")?.value;
10+
11+
if (!accessToken) {
12+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
13+
}
14+
15+
const response = await apiClient.get(`/forms/${params.formId}/applications/my-application`, {
16+
headers: {
17+
Authorization: `Bearer ${accessToken}`,
18+
},
19+
});
20+
21+
return NextResponse.json(response.data);
22+
} catch (error: unknown) {
23+
if (error instanceof AxiosError) {
24+
console.error(`GET /api/forms/${params.formId}/applications/myApplication error:`, error);
25+
if (error.response) {
26+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
27+
}
28+
}
29+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { AxiosError } from "axios";
2+
import { NextRequest, NextResponse } from "next/server";
3+
import apiClient from "@/lib/apiClient";
4+
5+
// 비회원의 내 지원 내역 조회
6+
export async function POST(req: NextRequest, { params }: { params: { formId: string } }) {
7+
try {
8+
const body = await req.json();
9+
const { name, phone, password } = body;
10+
11+
if (!name || !phone || !password) {
12+
return NextResponse.json({ message: "이름, 전화번호, 비밀번호가 필요합니다." }, { status: 400 });
13+
}
14+
15+
const response = await apiClient.post(`/forms/${params.formId}/applications/my-application/verify`, {
16+
name,
17+
phone,
18+
password,
19+
});
20+
21+
return NextResponse.json(response.data);
22+
} catch (error: unknown) {
23+
if (error instanceof AxiosError) {
24+
console.error(`POST /api/forms/${params.formId}/applications/myApplication/verify error:`, error);
25+
if (error.response) {
26+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
27+
}
28+
}
29+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
30+
}
31+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { AxiosError } from "axios";
2+
import { cookies } from "next/headers";
3+
import { NextRequest, NextResponse } from "next/server";
4+
import apiClient from "@/lib/apiClient";
5+
6+
// 지원하기
7+
export async function POST(req: NextRequest, { params }: { params: { formId: string } }) {
8+
try {
9+
const accessToken = cookies().get("accessToken")?.value;
10+
11+
if (!accessToken) {
12+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
13+
}
14+
15+
const body = await req.json();
16+
17+
const response = await apiClient.post(`/forms/${params.formId}/applications`, body, {
18+
headers: {
19+
Authorization: `Bearer ${accessToken}`,
20+
},
21+
});
22+
23+
return NextResponse.json(response.data);
24+
} catch (error: unknown) {
25+
if (error instanceof AxiosError) {
26+
console.error(`POST /api/forms/${params.formId}/applications error:`, error);
27+
if (error.response) {
28+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
29+
}
30+
}
31+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
32+
}
33+
}
34+
35+
// 지원 현황 목록 조회
36+
export async function GET(req: NextRequest, { params }: { params: { formId: string } }) {
37+
try {
38+
const accessToken = cookies().get("accessToken")?.value;
39+
40+
if (!accessToken) {
41+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
42+
}
43+
44+
const { searchParams } = new URL(req.url);
45+
const queryParams = {
46+
page: searchParams.get("page"),
47+
limit: searchParams.get("limit"),
48+
status: searchParams.get("status"),
49+
};
50+
51+
const response = await apiClient.get(`/forms/${params.formId}/applications`, {
52+
params: queryParams,
53+
headers: {
54+
Authorization: `Bearer ${accessToken}`,
55+
},
56+
});
57+
58+
return NextResponse.json(response.data);
59+
} catch (error: unknown) {
60+
if (error instanceof AxiosError) {
61+
console.error(`GET /api/forms/${params.formId}/applications error:`, error);
62+
if (error.response) {
63+
return NextResponse.json({ message: error.response.data.message }, { status: error.response.status });
64+
}
65+
}
66+
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
67+
}
68+
}

0 commit comments

Comments
 (0)