Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.data.domain.Slice
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PathVariable
Expand Down Expand Up @@ -114,4 +115,12 @@ interface ArticleApiV1 {
@RequestBody request: ReportRequest,
): ApiResult<Unit>

@Operation(
summary = "게시글 삭제",
description = "게시글을 삭제합니다."
)
@DeleteMapping("/{id}")
fun delete(
@PathVariable("id") id: Long,
): ApiResult<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ class ArticleController(
)
return ApiResult.noContent(path = "/v1/articles/$id/report")
}

override fun delete(id: Long): ApiResult<Unit> {
val userId = SecurityContextUtils.getUserId()
articleService.delete(userId, id)
return ApiResult.ok(path = "/v1/articles/$id")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ArticleService(
return@let authorVerifiedAddressIds.contains(article.address?.id)
} ?: false

roots.forEach { it.children.removeIf { it.deletedAt != null }}
roots.forEach { it.children.removeIf { it.deletedAt != null } }

return ArticleDetailResponse.of(
article = article,
Expand Down Expand Up @@ -353,4 +353,13 @@ class ArticleService(
article.increaseReportCount()
)
}

@Transactional
fun delete(userId: Long, articleId: Long) {
val article = articleRepository.findByIdOrThrow(articleId)
if (article.authUser?.id != userId) {
throw CustomException(CustomErrorContext.NOT_ARTICLE_AUTHOR)
}
articleRepository.delete(article)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class CustomErrorContext(

// 26xx: 게시글 관련 오류
NOT_FOUND_ARTICLE(HttpStatus.NOT_FOUND, 2600, "게시글을 찾을 수 없습니다."),
NOT_ARTICLE_AUTHOR(HttpStatus.BAD_REQUEST, 2601, "게시글 작성자가 아닙니다."),

// 27xx: 행동요령 관련 오류
NOT_FOUND_TIP_TYPE(HttpStatus.NOT_FOUND, 2700, "행동요령 유형을 찾을 수 없습니다."),
Expand Down
Loading