diff --git a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/api/controller/PostLikeController.java b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/api/controller/PostLikeController.java index 2d063f7..7495062 100644 --- a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/api/controller/PostLikeController.java +++ b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/api/controller/PostLikeController.java @@ -13,9 +13,9 @@ import org.springframework.web.bind.annotation.RestController; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.responses.ApiResponses; -import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; @RestController @@ -35,9 +35,9 @@ public class PostLikeController { @PostMapping("/{postId}") public ResponseEntity> like( @PathVariable Long postId, - @NotNull @UserId Long userId + @Parameter(hidden = true) @UserId Long userId ) { - postLikeFacade.like(postId, userId.longValue()); + postLikeFacade.like(postId, userId); return ResponseEntity.ok(ApiResponse.success(null)); } @@ -52,9 +52,9 @@ public ResponseEntity> like( @DeleteMapping("/{postId}") public ResponseEntity> cancelLike( @PathVariable Long postId, - @NotNull @UserId Long userId) { + @Parameter(hidden = true) @UserId Long userId) { - postLikeFacade.cancelLike(postId, userId.longValue()); + postLikeFacade.cancelLike(postId, userId); return ResponseEntity.ok(ApiResponse.success(null)); } } \ No newline at end of file diff --git a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/application/service/PostLikeService.java b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/application/service/PostLikeService.java index 5b3b601..f700b95 100644 --- a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/application/service/PostLikeService.java +++ b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/application/service/PostLikeService.java @@ -17,7 +17,7 @@ public class PostLikeService { private final PostLikeRepository postLikeRepository; public void like(final UserEntity user, final PostEntity post) { - validateNotSelfLike(user, post); + // validateNotSelfLike(user, post); if (postLikeRepository.existsByUserIdAndPostId(user.getUserId(), post.getPostId())) { throw new PostLikeBusinessException(PostLikeErrorCode.DUPLICATE_LIKE); @@ -30,18 +30,18 @@ public void like(final UserEntity user, final PostEntity post) { } public void cancelLike(UserEntity user, PostEntity post) { - validateNotSelfLike(user, post); + // validateNotSelfLike(user, post); - if (!postLikeRepository.existsByUserIdAndPostId(user.getUserId(), post.getPostId())) { + long deletedCount = postLikeRepository.deleteByUserIdAndPostId(user.getUserId(), post.getPostId()); + + if (deletedCount == 0) { throw new PostLikeBusinessException(PostLikeErrorCode.LIKE_NOT_FOUND); } - - postLikeRepository.deleteByUserIdAndPostId(user.getUserId(), post.getPostId()); } - private void validateNotSelfLike(UserEntity user, PostEntity post) { - if (post.getUser().getUserId().equals(user.getUserId())) { - throw new PostLikeBusinessException(PostLikeErrorCode.CANNOT_LIKE_OWN_POST); - } - } + // private void validateNotSelfLike(UserEntity user, PostEntity post) { + // if (post.getUser().getUserId().equals(user.getUserId())) { + // throw new PostLikeBusinessException(PostLikeErrorCode.CANNOT_LIKE_OWN_POST); + // } + // } } \ No newline at end of file diff --git a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/domain/repository/PostLikeRepository.java b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/domain/repository/PostLikeRepository.java index 95e874a..410ad67 100644 --- a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/domain/repository/PostLikeRepository.java +++ b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/domain/repository/PostLikeRepository.java @@ -12,5 +12,5 @@ public interface PostLikeRepository { List findAllByUserWithPostAndImages(Long userId); - void deleteByUserIdAndPostId(Long userId, Long postId); + int deleteByUserIdAndPostId(Long userId, Long postId); } \ No newline at end of file diff --git a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/PostLikeRepositoryImpl.java b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/PostLikeRepositoryImpl.java index 70ee244..6f7ba3d 100644 --- a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/PostLikeRepositoryImpl.java +++ b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/PostLikeRepositoryImpl.java @@ -27,8 +27,8 @@ public boolean existsByUserIdAndPostId(Long userId, Long postId) { } @Override - public void deleteByUserIdAndPostId(Long userId, Long postId) { - jpaRepository.deleteByUserIdAndPostIdQuery(userId, postId); + public int deleteByUserIdAndPostId(Long userId, Long postId) { + return jpaRepository.deleteByUserIdAndPostIdQuery(userId, postId); } @Override diff --git a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/SpringDataPostLikeRepository.java b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/SpringDataPostLikeRepository.java index 9be6c6e..23a8f4a 100644 --- a/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/SpringDataPostLikeRepository.java +++ b/src/main/java/org/sopt/pawkey/backendapi/domain/Post/infra/persistence/repository/SpringDataPostLikeRepository.java @@ -29,5 +29,5 @@ public interface SpringDataPostLikeRepository extends JpaRepository