Skip to content

Commit

Permalink
정보 등록 API 호출 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunJinNo committed Jul 11, 2024
1 parent b3199e9 commit e026199
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 40 deletions.
17 changes: 0 additions & 17 deletions src/app/api/informations/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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
Expand Down
55 changes: 32 additions & 23 deletions src/containers/informations/write/InformationEditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -108,6 +116,7 @@ const InformationEditorContainer = () => {
});

if (!response.ok) {
alert("테스트 실패");
throw new Error("Failed to write data.");
}

Expand Down

0 comments on commit e026199

Please sign in to comment.