From 645ed00471fc92b43c1bf96c858cab9ea54b78f2 Mon Sep 17 00:00:00 2001 From: Lee jin <83453646+j-nary@users.noreply.github.com> Date: Sun, 3 Nov 2024 14:15:25 +0900 Subject: [PATCH] =?UTF-8?q?DELETE,=20POST,=20PUT=20post/v2=20API=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98=20(#943)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: DELETE /post/v2 * refactor: POST /post/v2/like * refactor: PUT post/v2 --- pages/post/index.tsx | 2 +- src/api/post/hooks.ts | 4 ++-- src/api/post/index.ts | 15 ++++++++------- .../meetingList/Advertisement/PostDeleteModal.tsx | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pages/post/index.tsx b/pages/post/index.tsx index b01aeb08..719924f4 100644 --- a/pages/post/index.tsx +++ b/pages/post/index.tsx @@ -95,7 +95,7 @@ export default function PostPage() { const { mutate: togglePostLike } = useMutationPostLike(query.id as string); const { mutate: mutateDeletePost } = useMutation({ - mutationFn: () => DELETE('/post/v1/{postId}', { params: { path: { postId: post!.id } } }), + mutationFn: () => DELETE('/post/v2/{postId}', { params: { path: { postId: post!.id } } }), onSuccess: () => router.replace(`/detail?id=${post?.meeting.id}`), }); diff --git a/src/api/post/hooks.ts b/src/api/post/hooks.ts index 82f3ce16..c290a52e 100644 --- a/src/api/post/hooks.ts +++ b/src/api/post/hooks.ts @@ -30,7 +30,7 @@ export const useMutationUpdateLike = (take: number, meetingId?: number) => { const queryClient = useQueryClient(); return useMutation({ - mutationFn: (postId: number) => postLike(String(postId)), + mutationFn: (postId: number) => postLike(postId), onMutate: async postId => { await queryClient.cancelQueries(['getPosts', take, meetingId]); @@ -77,7 +77,7 @@ export const useMutationPostLike = (queryId: string) => { return useMutation({ mutationKey: ['getPost', queryId], - mutationFn: () => postLike(queryId), + mutationFn: () => postLike(+queryId), onMutate: async () => { const previousPost = queryClient.getQueryData(['getPost', queryId]) as postType; diff --git a/src/api/post/index.ts b/src/api/post/index.ts index cc032775..2c613d80 100644 --- a/src/api/post/index.ts +++ b/src/api/post/index.ts @@ -23,10 +23,9 @@ export const createPost = async (formData: FormCreateType) => { }; export const editPost = async (postId: string, formData: FormEditType) => { - const { data } = await api.put>>( - `/post/v1/${postId}`, - formData - ); + type editPostType = + paths['/post/v2/{postId}']['put']['responses']['200']['content']['application/json;charset=UTF-8']; + const { data } = await api.put(`/post/v2/${postId}`, formData); return data; }; @@ -42,9 +41,11 @@ export const getPost = async (postId: string) => { return data; }; -export const postLike = async (queryId: string) => { - const { POST } = apiV2.get(); - return await POST('/post/v1/{postId}/like', { params: { path: { postId: Number(queryId) } } }); +export const postLike = async (postId: number) => { + type postListType = + paths['/post/v2/{postId}/like']['post']['responses']['201']['content']['application/json;charset=UTF-8']; + const { data } = await api.post(`/post/v2/${postId}/like`); + return data; }; export const deleteComment = async (commentId: number) => { diff --git a/src/components/page/meetingList/Advertisement/PostDeleteModal.tsx b/src/components/page/meetingList/Advertisement/PostDeleteModal.tsx index d838823e..150b2982 100644 --- a/src/components/page/meetingList/Advertisement/PostDeleteModal.tsx +++ b/src/components/page/meetingList/Advertisement/PostDeleteModal.tsx @@ -19,7 +19,7 @@ const PostDeleteModal = ({ isOpen, close, postId, meetingId }: PostDeleteModalPr const { DELETE } = apiV2.get(); const { mutate: mutateDeletePost } = useMutation({ - mutationFn: () => DELETE('/post/v1/{postId}', { params: { path: { postId: postId } } }), + mutationFn: () => DELETE('/post/v2/{postId}', { params: { path: { postId: postId } } }), onSuccess: () => queryClient.invalidateQueries(['getPosts']), //todo: 지금은 getPosts 로 시작하는 모든 query 가 invalidate 됨. });