-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from TripInfoWeb/dev_diary
Feat: 여행일기
- Loading branch information
Showing
35 changed files
with
906 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { CreateDiaryRequestDto } from "@/types/DiaryDto"; | ||
import { revalidateTag } from "next/cache"; | ||
import { NextRequest } from "next/server"; | ||
|
||
// 일기 작성 | ||
export async function POST(request: NextRequest) { | ||
try { | ||
const cookie = request.cookies.get("access_token"); | ||
const body: CreateDiaryRequestDto = await request.json(); | ||
|
||
const response = await fetch( | ||
`${process.env.LOCAL_BACKEND_URL}/api/diary/create`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Cookie: `${cookie?.name}=${cookie?.value}`, | ||
}, | ||
body: JSON.stringify(body), | ||
cache: "no-store", | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
revalidateTag("getDiaryList"); | ||
return response; | ||
} catch (err: any) { | ||
return new Response(JSON.stringify({ error: "Failed to write data." }), { | ||
status: 500, // Internal Server Error | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { revalidateTag } from "next/cache"; | ||
import { NextRequest } from "next/server"; | ||
|
||
/** | ||
* 일기 삭제 | ||
*/ | ||
export async function DELETE( | ||
request: NextRequest, | ||
{ params }: { params: { id: string } }, | ||
) { | ||
try { | ||
const cookie = request.cookies.get("access_token"); | ||
const response = await fetch( | ||
`${process.env.LOCAL_BACKEND_URL}/api/diary/delete/${params.id}`, | ||
{ | ||
method: "DELETE", | ||
headers: { | ||
Cookie: `${cookie?.name}=${cookie?.value}`, | ||
}, | ||
cache: "no-store", | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
revalidateTag("getDiaryList"); | ||
return response; | ||
} catch (err) { | ||
return new Response("Failed to delete data.", { | ||
status: 500, // Internal Server Error, | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { UpdateDiaryRequestDto } from "@/types/DiaryDto"; | ||
import { revalidateTag } from "next/cache"; | ||
import { NextRequest } from "next/server"; | ||
|
||
/** | ||
* 일기 수정 | ||
*/ | ||
export async function PUT( | ||
request: NextRequest, | ||
{ params }: { params: { id: string } }, | ||
) { | ||
try { | ||
const cookie = request.cookies.get("access_token"); | ||
const body: UpdateDiaryRequestDto = await request.json(); | ||
|
||
const response = await fetch( | ||
`${process.env.LOCAL_BACKEND_URL}/api/diary/update/${params.id}`, | ||
{ | ||
method: "PUT", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Cookie: `${cookie?.name}=${cookie?.value}`, | ||
}, | ||
body: JSON.stringify(body), | ||
cache: "no-store", | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
revalidateTag("getDiaryList"); | ||
revalidateTag(`getDiary/${params.id}`); | ||
return response; | ||
} catch (err) { | ||
return new Response(JSON.stringify({ error: "Failed to update data." }), { | ||
status: 500, // Internal Server Error | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { NextRequest } from "next/server"; | ||
|
||
// 이미지 업로드 | ||
export async function POST(request: NextRequest) { | ||
try { | ||
const cookie = request.cookies.get("access_token"); | ||
const formData = await request.formData(); | ||
|
||
const response = await fetch( | ||
`${process.env.LOCAL_BACKEND_URL}/api/image/upload`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
Cookie: `${cookie?.name}=${cookie?.value}`, | ||
}, | ||
body: formData, | ||
cache: "no-store", | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
return response; | ||
} catch (err: any) { | ||
return new Response(JSON.stringify({ error: err.message }), { | ||
status: 500, // Internal Server Error | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import PagePath from "@/components/common/PagePath"; | ||
import DiaryViewerSkeleton from "@/components/skeleton/diary/detail/DiaryViewerSkeleton"; | ||
|
||
export default function Loading() { | ||
return ( | ||
<div className="flex w-full flex-col items-center"> | ||
<PagePath first="여행 일기" second="일기 상세" /> | ||
<DiaryViewerSkeleton /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import PagePath from "@/components/common/PagePath"; | ||
import DiaryEditorContainer from "@/containers/diary/edit/DiaryEditorContainer"; | ||
import { GetDiaryResponseDto } from "@/types/DiaryDto"; | ||
import { cookies } from "next/headers"; | ||
|
||
async function getDiary(id: number) { | ||
const cookie = cookies().get("access_token"); | ||
const response = await fetch( | ||
`${process.env.LOCAL_BACKEND_URL}/api/diary/${id}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
Cookie: `${cookie?.name}=${cookie?.value}`, | ||
}, | ||
next: { revalidate: 60, tags: [`getDiary/${id}`] }, | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
return response.json() as Promise<GetDiaryResponseDto>; | ||
} | ||
|
||
interface Props { | ||
params: { id: string }; | ||
} | ||
|
||
export async function generateMetadata({ params: { id } }: Props) { | ||
const diaryId = Number(id); | ||
if (diaryId <= 0 || !Number.isSafeInteger(diaryId)) { | ||
throw new Error("Not Found"); | ||
} | ||
|
||
return { | ||
title: `일기 수정하기 - ${diaryId}`, | ||
description: "Solitour의 여행 일기 수정 페이지", | ||
}; | ||
} | ||
|
||
export default async function page({ params: { id } }: Props) { | ||
const diaryId = Number(id); | ||
if (diaryId <= 0 || !Number.isSafeInteger(diaryId)) { | ||
throw new Error("Not Found"); | ||
} | ||
|
||
const data = await getDiary(diaryId); | ||
|
||
return ( | ||
<div className="flex w-full flex-col items-center"> | ||
<PagePath first="여행 일기" second="일기 수정하기" /> | ||
<DiaryEditorContainer diaryData={data} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.