Skip to content

Commit

Permalink
Merge pull request #98 from Seasoning-Today/fix/cancle-article-like-e…
Browse files Browse the repository at this point in the history
…rror

fix: 기록장 좋아요 취소 오류 해결
  • Loading branch information
csct3434 authored Mar 21, 2024
2 parents a79b891 + b747ae3 commit d818022
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d818022

Please sign in to comment.