Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ontend into feat/#940
  • Loading branch information
borimong committed Nov 3, 2024
2 parents 58a102f + cc97f3b commit 61a6989
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@sopt-makers/colors": "^3.0.2",
"@sopt-makers/fonts": "^2.0.1",
"@sopt-makers/icons": "^1.0.5",
"@sopt-makers/playground-common": "^1.5.2",
"@sopt-makers/playground-common": "^1.6.2",
"@sopt-makers/ui": "^2.4.4",
"@stitches/react": "^1.2.8",
"@tanstack/react-query": "^4.10.3",
Expand Down
2 changes: 1 addition & 1 deletion pages/post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`),
});

Expand Down
4 changes: 2 additions & 2 deletions src/api/post/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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;

Expand Down
15 changes: 8 additions & 7 deletions src/api/post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ export const createPost = async (formData: FormCreateType) => {
};

export const editPost = async (postId: string, formData: FormEditType) => {
const { data } = await api.put<Data<Pick<PostResponse, 'id' | 'title' | 'contents' | 'updatedDate' | 'images'>>>(
`/post/v1/${postId}`,
formData
);
type editPostType =
paths['/post/v2/{postId}']['put']['responses']['200']['content']['application/json;charset=UTF-8'];
const { data } = await api.put<editPostType>(`/post/v2/${postId}`, formData);
return data;
};

Expand All @@ -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<postListType>(`/post/v2/${postId}/like`);
return data;
};

export const deleteComment = async (commentId: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 됨.
});
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6764,9 +6764,9 @@ __metadata:
languageName: node
linkType: hard

"@sopt-makers/playground-common@npm:^1.5.2":
version: 1.5.2
resolution: "@sopt-makers/playground-common@npm:1.5.2"
"@sopt-makers/playground-common@npm:^1.6.2":
version: 1.6.2
resolution: "@sopt-makers/playground-common@npm:1.6.2"
dependencies:
"@emotion/react": "npm:^11.9.0"
"@emotion/styled": "npm:^11.8.1"
Expand All @@ -6777,7 +6777,7 @@ __metadata:
peerDependencies:
react: ^16.8 || ^17.0 || ^18.0
react-dom: ^16.8 || ^17.0 || ^18.0
checksum: 10c0/c02a6f33114d76e2d8e34bd7edcd8c27533eef9696405c3a0bdd4aad2305fdc519b40361f5b36a670600ba8b5b7d2445fcc28a0a74c7847320b0daf0738c6242
checksum: 10c0/98958ea6b365ef7793d9a07fd7721e5137d20bf2b2095c86f71abd1940bacd97f50985c44e9519cbe03d81ae55c0c567e09765a1831ca1a377b17e63f6b86ef4
languageName: node
linkType: hard

Expand Down Expand Up @@ -20702,7 +20702,7 @@ __metadata:
"@sopt-makers/colors": "npm:^3.0.2"
"@sopt-makers/fonts": "npm:^2.0.1"
"@sopt-makers/icons": "npm:^1.0.5"
"@sopt-makers/playground-common": "npm:^1.5.2"
"@sopt-makers/playground-common": "npm:^1.6.2"
"@sopt-makers/ui": "npm:^2.4.4"
"@stitches/react": "npm:^1.2.8"
"@storybook/addon-essentials": "npm:^8.1.11"
Expand Down

0 comments on commit 61a6989

Please sign in to comment.