Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O2F-530 O2F-531 O2F-532 [FEAT] 게시글 삭제 구현 #18

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/apis/ootd/PostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ export const updatePost = async (postId: number, postUpdateRequest: PostUpdateRe
}
}

export const deletePost = async (postId: number)
: Promise<void> => {
try {
await authAxiosInstance.delete(`/posts/${postId}`)
} catch (error) {
if (error instanceof AxiosError) {
if (error.response) {
if (error.response.status >= 400) {
alert(error.response.data.message)
console.error(`Client Error=${error.response.data.message}`)
}
if (error.response.status < 500) {
alert('서버 내부 오류')
console.error('Internal Server Error')
}
}
}
throw error
}
}

export const getPostDetail = async (postId: number)
: Promise<PostDetailResponse> => {
try {
Expand Down
10 changes: 8 additions & 2 deletions src/views/OOTDDetailView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { onBeforeMount, ref } from 'vue'
import type { PostDetailHashTagResponse, PostDetailResponse, PostImageProductDetailResponse } from '@/apis/ootd/PostDto'
import { onBeforeRouteLeave, useRoute } from 'vue-router'
import { getPostDetail } from '@/apis/ootd/PostService'
import { deletePost, getPostDetail } from '@/apis/ootd/PostService'
import OOTDPostCommentComponent from '@/components/ootd/OOTDPostCommentComponent.vue'
import { usePostLikeStore } from '@/stores/postlike/PostLikeStore'
import router from '@/router'
Expand Down Expand Up @@ -142,6 +142,12 @@ const onUpdateBtnClick = async () => {
}))
await router.push({ path: `/ootds/${postId.value}/edit` })
}

const onDeleteBtnClick = async () => {
await deletePost(postId.value)
alert("게시글이 삭제되었습니다.")
await router.push({ path: '/ootds' })
}
</script>

<template>
Expand All @@ -161,7 +167,7 @@ const onUpdateBtnClick = async () => {
수정
</div>
</div>
<div class='ootd-detail-header-delete-button-wrapper'>
<div class='ootd-detail-header-delete-button-wrapper' @click='onDeleteBtnClick'>
<div class='ootd-detail-header-delete-button-text'>
삭제
</div>
Expand Down