Skip to content

Commit

Permalink
Merge pull request #177 from pknu-wap/fix/찐찐찐막
Browse files Browse the repository at this point in the history
🐛Fix/찐찐찐막
  • Loading branch information
FhRh committed Nov 30, 2023
2 parents dfbbb7d + a866f14 commit bd2bbd1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@

public interface PostLikeRepository extends JpaRepository<PostLike,Long> {

@Query("SELECT l FROM PostLike l JOIN l.post p WHERE p.id = :postId AND p.user.id = :userId")
Optional<PostLike> findByPostAndUser(@Param("postId") Long postId,
@Param("userId") Long userId);
Optional<PostLike> findPostLikeByPostAndUser(Post post, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public PostReadResponse readPost(UserPrincipal userPrincipal, Long postId) throw
if (scrapRepository.findByUserIdAndPostId(user.getId(), post.getId()).isPresent())
isScraped = true;

if (postLikeRepository.findByPostAndUser(post.getId(), user.getId()).isPresent())
if (postLikeRepository.findPostLikeByPostAndUser(post, user).isPresent())
isLiked = true;

if (post.getUser().equals(user))
Expand Down Expand Up @@ -290,7 +290,7 @@ public String clickLike(UserPrincipal userPrincipal, Long postId) {
Post post = postRepository.findById(postId).get();
User currentUser = userRepository.findById(userPrincipal.getId()).get();

Optional<PostLike> postLikeOptional = postLikeRepository.findByPostAndUser(post.getId(), currentUser.getId());
Optional<PostLike> postLikeOptional = postLikeRepository.findPostLikeByPostAndUser(post, currentUser);
if (postLikeOptional.isPresent()) {

post.setLikesCount(post.getLikesCount() - 1);
Expand Down

0 comments on commit bd2bbd1

Please sign in to comment.