diff --git a/src/app/api/gathering/applyHandler/route.ts b/src/app/api/gathering/apply/route.ts similarity index 61% rename from src/app/api/gathering/applyHandler/route.ts rename to src/app/api/gathering/apply/route.ts index 0abe4913..7c9ce7e7 100644 --- a/src/app/api/gathering/applyHandler/route.ts +++ b/src/app/api/gathering/apply/route.ts @@ -9,8 +9,6 @@ export async function POST( const url = new URL(request.url); const id = url.searchParams.get("id"); - - // Back-end API 호출 const response = await fetch( `${process.env.BACKEND_URL}/api/gatherings/applicants/${id}`, { @@ -37,44 +35,42 @@ export async function POST( } } -// export async function PUT( -// request: NextRequest, -// { params }: { params: { id: string } }, -// ) { -// try { -// const cookie = request.cookies.get("access_token"); +export async function PUT( + request: NextRequest, +) { + try { + const cookie = request.cookies.get("access_token"); + const data = await request.json(); -// // Back-end API 호출 -// const response = await fetch( -// `${process.env.BACKEND_URL}/api/gatherings/applicants/${params.id}`, -// { -// method: "PUT", -// headers: { -// Cookie: `${cookie?.name}=${cookie?.value}`, -// "Content-Type": "application/json", -// }, -// cache: "no-store", -// }, -// ); + const response = await fetch( + `${process.env.BACKEND_URL}/api/gatherings/applicants/${data.applyId}`, + { + method: "PUT", + headers: { + Cookie: `${cookie?.name}=${cookie?.value}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + userId: data.userId, + gatheringStatus: data.gatheringStatus, + }), + cache: "no-store", + }, + ); -// if (!response.ok) { -// throw new Error(response.statusText); -// } -// await revalidatePath(`/gathering/${params.id}`); -// // return NextResponse.redirect( -// // new URL(`/getGathering/${params.id}`), -// // ); - -// return response; -// } catch (e) { -// return new Response(JSON.stringify({ error: "Failed to update data." }), { -// status: 500, -// headers: { -// "Content-Type": "application/json", -// }, -// }); -// } -// } + if (!response.ok) { + throw new Error(response.statusText); + } + return response; + } catch (e) { + return new Response(JSON.stringify({ error: "Failed to update data." }), { + status: 500, + headers: { + "Content-Type": "application/json", + }, + }); + } +} // * 모임 글 삭제 export async function DELETE( diff --git a/src/containers/gathering/GatheringSupportManagementContainer.tsx b/src/containers/gathering/GatheringSupportManagementContainer.tsx index 3da87b35..609bcd25 100644 --- a/src/containers/gathering/GatheringSupportManagementContainer.tsx +++ b/src/containers/gathering/GatheringSupportManagementContainer.tsx @@ -12,13 +12,13 @@ const GatheringSupportManagementContainer = ({ const params = useParams(); const applyGathering = async () => { - const res = await fetch(`/api/gathering/applyHandler?id=${params.id}`, { + const res = await fetch(`/api/gathering/apply?id=${params.id}`, { method: "POST" }) } const cancelGathering = async () => { - const res = await fetch(`/api/gathering/applyHandler?id=${params.id}`, { + const res = await fetch(`/api/gathering/apply?id=${params.id}`, { method: "DELETE", }); }