From e0261990fecfa31ac5c24a1aa12c87f4ce9fc118 Mon Sep 17 00:00:00 2001 From: HyunJinNo Date: Fri, 12 Jul 2024 00:39:40 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=93=B1=EB=A1=9D=20API?= =?UTF-8?q?=20=ED=98=B8=EC=B6=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/informations/route.ts | 17 ------ .../write/InformationEditorContainer.tsx | 55 +++++++++++-------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/app/api/informations/route.ts b/src/app/api/informations/route.ts index 3c5ccf5e..25bb6964 100644 --- a/src/app/api/informations/route.ts +++ b/src/app/api/informations/route.ts @@ -7,19 +7,14 @@ export async function POST(request: NextRequest) { const cookie = request.cookies.get("access_token"); const formData = await request.formData(); - // TODO: 삭제 필요 console.log("TEST 정보 글 작성"); console.log(formData); - /* // Back-end API 호출 const response = await fetch( `${process.env.BACKEND_URL}/api/informations`, { method: "POST", - headers: { - Cookie: `${cookie?.name}=${cookie?.value}`, - }, body: formData, cache: "no-store", }, @@ -34,18 +29,6 @@ export async function POST(request: NextRequest) { revalidateTag("getInformationList"); return response; - */ - - // TODO: 삭제 필요 - return new Response( - JSON.stringify({ title: "1", content: "2", tips: ["3", "4"] }), - { - status: 200, - headers: { - "Content-Type": "application/json", - }, - }, - ); } catch (e) { return new Response(JSON.stringify({ error: "Failed to write data." }), { status: 500, // Internal Server Error diff --git a/src/containers/informations/write/InformationEditorContainer.tsx b/src/containers/informations/write/InformationEditorContainer.tsx index c18ba9f4..e49368fa 100644 --- a/src/containers/informations/write/InformationEditorContainer.tsx +++ b/src/containers/informations/write/InformationEditorContainer.tsx @@ -67,35 +67,43 @@ const InformationEditorContainer = () => { return; } + // TODO: 수정 필요 const formData = new FormData(); - formData.append("userId", validatedFields.data.userId.toString()); - formData.append("informationTitle", validatedFields.data.informationTitle); formData.append( - "informationAddress", - validatedFields.data.informationAddress, + "request", + new Blob( + [ + JSON.stringify({ + informationTitle: validatedFields.data.informationTitle, + informationAddress: validatedFields.data.informationAddress, + informationContent: validatedFields.data.informationContent, + informationTips: validatedFields.data.tips.join(" "), + userId: 1, // TODO: 수정 필요 + placeRegisterRequest: { + searchId: validatedFields.data.placeId, + name: validatedFields.data.placeName, + xAxis: validatedFields.data.placeXAxis, + yAxis: validatedFields.data.placeYAxis, + address: validatedFields.data.informationAddress, + }, + categoryId: 1, + zoneCategoryId: 2, + tagRegisterRequests: validatedFields.data.hashtags.map( + (tag, index) => ({ + [index]: tag, + }), + ), + }), + ], + { + type: "application/json", + }, + ), ); - formData.append("province", validatedFields.data.province); - formData.append("city", validatedFields.data.city); - formData.append("placeId", validatedFields.data.placeId); - formData.append("placeXAxis", validatedFields.data.placeXAxis); - formData.append("placeYAxis", validatedFields.data.placeYAxis); - formData.append("placeName", validatedFields.data.placeName); - formData.append("category", validatedFields.data.category); - formData.append("subCategory", validatedFields.data.subCategory); - formData.append("thumbnailImage", validatedFields.data.thumbnailImage); + formData.append("thumbNailImage", validatedFields.data.thumbnailImage); validatedFields.data.contentImages?.forEach((contentImage) => { formData.append("contentImages", contentImage); }); - formData.append( - "informationContent", - validatedFields.data.informationContent, - ); - validatedFields.data.hashtags.forEach((hashtag) => { - formData.append("hashtags", hashtag); - }); - validatedFields.data.tips.forEach((tip) => { - formData.append("informationTips", tip); - }); // headers: { // "Content-Type": "multipart/form-data" @@ -108,6 +116,7 @@ const InformationEditorContainer = () => { }); if (!response.ok) { + alert("테스트 실패"); throw new Error("Failed to write data."); }