Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,9 +35,9 @@ public class PostLikeController {
@PostMapping("/{postId}")
public ResponseEntity<ApiResponse<Void>> 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));
}

Expand All @@ -52,9 +52,9 @@ public ResponseEntity<ApiResponse<Void>> like(
@DeleteMapping("/{postId}")
public ResponseEntity<ApiResponse<Void>> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public void like(final UserEntity user, final PostEntity post) {
public void cancelLike(UserEntity user, PostEntity 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface PostLikeRepository {

List<PostLikeEntity> findAllByUserWithPostAndImages(Long userId);

void deleteByUserIdAndPostId(Long userId, Long postId);
int deleteByUserIdAndPostId(Long userId, Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public interface SpringDataPostLikeRepository extends JpaRepository<PostLikeEnti

@Modifying
@Query("DELETE FROM PostLikeEntity pl WHERE pl.user.userId = :userId AND pl.post.postId = :postId")
void deleteByUserIdAndPostIdQuery(@Param("userId") Long userId, @Param("postId") Long postId);
int deleteByUserIdAndPostIdQuery(@Param("userId") Long userId, @Param("postId") Long postId);
}