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/app/gathering/[id]/page.tsx b/src/app/gathering/[id]/page.tsx index 46e1f6b1..e6299e04 100644 --- a/src/app/gathering/[id]/page.tsx +++ b/src/app/gathering/[id]/page.tsx @@ -1,6 +1,7 @@ import GatheringRecommendationList from "@/components/gathering/GatheringRecommendationList"; import GatheringViewerContainer from "@/components/gathering/GatheringViewerContainer"; import { GatheringDetailResponseDto } from "@/types/GatheringDto"; +import { cookies } from "next/headers"; import { NextResponse } from "next/server"; interface PageProps { @@ -8,12 +9,15 @@ interface PageProps { } async function getGathering(id: number): Promise { + const cookie = cookies().get("access_token"); try { const response = await fetch( `${process.env.BACKEND_URL}/api/gatherings/${id}`, { - headers: { "Content-Type": "application/json" }, - credentials: "include", + method: "GET", + headers: { + Cookie: `${cookie?.name}=${cookie?.value}`, + }, cache: "no-store", // next: { revalidate: 60, tags: [`gathering/${id}`] }, }, diff --git a/src/app/gathering/page.tsx b/src/app/gathering/page.tsx index 586f6c14..a6373d21 100644 --- a/src/app/gathering/page.tsx +++ b/src/app/gathering/page.tsx @@ -20,8 +20,6 @@ async function getData() { }, ); - console.log("page.tsx 파일 : ", res.status); - if (!res.ok) { throw new Error("Failed to fetch data"); } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 917e3139..3389764c 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -32,7 +32,6 @@ export default function RootLayout({ - {/* */}
diff --git a/src/components/gathering/GatheringApplicantList.tsx b/src/components/gathering/GatheringApplicantList.tsx index f10801d7..0c5ba51e 100644 --- a/src/components/gathering/GatheringApplicantList.tsx +++ b/src/components/gathering/GatheringApplicantList.tsx @@ -5,19 +5,24 @@ interface IApplicant { nickname: string; age: number; sex: "male" | "female"; + id: number; }; gatheringStatus: "WAIT" | "CONSENT" | "REFUSE"; } interface IGatheringApplicantList { applicants: IApplicant[]; + updateGatheringApplicantStatus: ( + status: "WAIT" | "CONSENT" | "REFUSE", + userId: number, + ) => void; } const GatheringApplicantList = (props: IGatheringApplicantList) => { return ( -
-
-
+
+
+
프로필 이미지
@@ -28,43 +33,71 @@ const GatheringApplicantList = (props: IGatheringApplicantList) => { 모임 신청 상태
- {props.applicants.map((applicant, index) => ( -
-
- Profile +
+ {props.applicants.map((applicant, index) => ( +
+
+ Profile +
+
+ {applicant.userGatheringResponse.nickname} +
+
+ {applicant.userGatheringResponse.age}년 + + {"("} + {new Date().getFullYear() - applicant.userGatheringResponse.age} + 살{")"} + +
+
+ {applicant.userGatheringResponse.sex === "male" ? "남성" : "여성"} +
+
+ + + +
-
- {applicant.userGatheringResponse.nickname} -
-
- {applicant.userGatheringResponse.age}년 -
-
- {applicant.userGatheringResponse.sex === "male" ? "남성" : "여성"} -
-
- - - -
-
- ))} + ))} +
); }; diff --git a/src/components/gathering/GatheringViewerContainer.tsx b/src/components/gathering/GatheringViewerContainer.tsx index 52daed3d..b08e61b2 100644 --- a/src/components/gathering/GatheringViewerContainer.tsx +++ b/src/components/gathering/GatheringViewerContainer.tsx @@ -1,7 +1,6 @@ "use client" import useModalState from "@/hooks/useModalState"; -import useAuthStore from "@/store/authStore"; import { GatheringDetailResponseDto } from "@/types/GatheringDto"; import GatheringViewer from "./GatheringViewer"; @@ -12,7 +11,6 @@ interface IGatheringViewerContainer { const GatheringViewerContainer = ({ data, postId }: IGatheringViewerContainer) => { const modalState = useModalState(); - const authStore = useAuthStore(); return ( { + (props: IGatheringApplicantListContainer) => { const authStore = useAuthStore(); - if (postUserId == authStore.id) { - return + const [applicants, setApplicants] = useState(props.applicants); + const params = useParams(); + + + const updateGatheringApplicantStatus = async ( + status: "WAIT" | "CONSENT" | "REFUSE", + userId: number, + ) => { + const res = await fetchWithAuth(`/api/gathering/apply`, { + method: "PUT", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + userId: userId, + gatheringStatus: status, + applyId: params.id, + }), + }); + + if (res.ok) { + const temp = applicants.map((i) => { + if (i.userGatheringResponse.id == userId) { + i.gatheringStatus = status; + } + return i; + }); + setApplicants(temp); + } + }; + + if (props.postUserId == authStore.id && applicants) { + return } return <>; + }; export default GatheringApplicantListContainer \ No newline at end of file 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", }); }