From b747ae3de5a43dd7fa32d8a6a7724fa6f0216688 Mon Sep 17 00:00:00 2001 From: csct3434 Date: Thu, 21 Mar 2024 11:46:58 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B8=B0=EB=A1=9D=EC=9E=A5=20=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=20=EC=B7=A8=EC=86=8C=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seasoning/article/service/ArticleLikeService.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/today/seasoning/seasoning/article/service/ArticleLikeService.java b/src/main/java/today/seasoning/seasoning/article/service/ArticleLikeService.java index e9c8b2b..5d6a626 100644 --- a/src/main/java/today/seasoning/seasoning/article/service/ArticleLikeService.java +++ b/src/main/java/today/seasoning/seasoning/article/service/ArticleLikeService.java @@ -37,19 +37,17 @@ public void doLike(Long userId, Long articleId) { articleLikeRepository.save(new ArticleLike(article, user)); if (user != author) { - applicationEventPublisher.publishEvent(new ArticleLikedEvent(user.getId(), author.getId(), articleId)); + ArticleLikedEvent articleLikedEvent = new ArticleLikedEvent(user.getId(), author.getId(), articleId); + applicationEventPublisher.publishEvent(articleLikedEvent); } } } public void cancelLike(Long userId, Long articleId) { Article article = articleRepository.findByIdOrElseThrow(articleId); - validatePermission(userId, article); - - if(articleLikeRepository.findByArticleAndUser(articleId, userId).isPresent()) { - articleLikeRepository.deleteById(articleId); - } + articleLikeRepository.findByArticleAndUser(articleId, userId) + .ifPresent(articleLike -> articleLikeRepository.deleteById(articleLike.getId())); } private void validatePermission(Long userId, Article article) {