Skip to content

Commit

Permalink
Merge pull request #18 from lotteon2/O2F-428-Frontend-SNS-/feat/delet…
Browse files Browse the repository at this point in the history
…e-post

O2F-530 O2F-531 O2F-532 [FEAT] 게시글 삭제 구현
  • Loading branch information
wakkpu authored Dec 5, 2023
2 parents 752c8fe + 92de0ac commit 69cb7c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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

0 comments on commit 69cb7c5

Please sign in to comment.