From 459b4bffc2c7b83d311ade5f77089f2d314b3336 Mon Sep 17 00:00:00 2001 From: tmddus2 Date: Sat, 10 Aug 2024 16:50:31 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94=20=EC=A4=91=EB=B3=B5=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/repository/FilterLikeRepository.java | 2 ++ .../domain/filter/service/FilterService.java | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/repository/FilterLikeRepository.java b/purithm/src/main/java/com/example/purithm/domain/filter/repository/FilterLikeRepository.java index c85168e..722e78a 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/repository/FilterLikeRepository.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/repository/FilterLikeRepository.java @@ -17,4 +17,6 @@ public interface FilterLikeRepository extends JpaRepository { + "from FilterLike fl\n" + "where fl.filter = :filter") int getLikes(@Param("filter") Filter filter); + + boolean existsByFilterIdAndUserId(Long filterId, Long userId); } diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java b/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java index e822e06..46f0849 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java @@ -134,15 +134,17 @@ public IOSFilterDetailDto getFilterIOSDetail(Long filterId) { } public void likeFilter(Long userId, Long filterId) { - Filter filter = filterRepository.findById(filterId) - .orElseThrow(() -> CustomException.of(Error.NOT_FOUND_ERROR)); - User user = userRepository.findById(userId) - .orElseThrow(() -> CustomException.of(Error.NOT_FOUND_ERROR)); + if (!filterLikeRepository.existsByFilterIdAndUserId(filterId, userId)) { + Filter filter = filterRepository.findById(filterId) + .orElseThrow(() -> CustomException.of(Error.NOT_FOUND_ERROR)); + User user = userRepository.findById(userId) + .orElseThrow(() -> CustomException.of(Error.NOT_FOUND_ERROR)); - FilterLike like = FilterLike.builder() - .filter(filter).user(user).build(); + FilterLike like = FilterLike.builder() + .filter(filter).user(user).build(); - filterLikeRepository.save(like); + filterLikeRepository.save(like); + } } @Transactional