-
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 #282 from TripInfoWeb/dev_diary
Refactor: 일기 수정 및 삭제 API를 Path Parameter 방식으로 변경
- Loading branch information
Showing
4 changed files
with
62 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 } }, | ||
) { | ||
const cookie = request.cookies.get("access_token"); | ||
const body: UpdateDiaryRequestDto = await request.json(); | ||
|
||
const response = await fetch( | ||
`${process.env.BACKEND_URL}/api/diary/${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; | ||
} | ||
|
||
/** | ||
* 일기 삭제 | ||
*/ | ||
export async function DELETE( | ||
request: NextRequest, | ||
{ params }: { params: { id: string } }, | ||
) { | ||
const cookie = request.cookies.get("access_token"); | ||
const response = await fetch( | ||
`${process.env.BACKEND_URL}/api/diary/${params.id}`, | ||
{ | ||
method: "DELETE", | ||
headers: { | ||
Cookie: `${cookie?.name}=${cookie?.value}`, | ||
}, | ||
cache: "no-store", | ||
}, | ||
); | ||
|
||
revalidateTag("getDiaryList"); | ||
return response; | ||
} |
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
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