From 4e12b622ce8a90b1bc1f3010823518128e8e780e Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Wed, 9 Jul 2025 18:35:59 +0800 Subject: [PATCH] Allow multiple reactions per user --- src/main/java/com/openisle/model/Reaction.java | 6 +----- .../java/com/openisle/service/ReactionService.java | 10 ---------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/main/java/com/openisle/model/Reaction.java b/src/main/java/com/openisle/model/Reaction.java index 9fb71d8c1..b51e92759 100644 --- a/src/main/java/com/openisle/model/Reaction.java +++ b/src/main/java/com/openisle/model/Reaction.java @@ -12,11 +12,7 @@ import lombok.Setter; @Getter @Setter @NoArgsConstructor -@Table(name = "reactions", - uniqueConstraints = { - @UniqueConstraint(columnNames = {"user_id", "post_id", "type"}), - @UniqueConstraint(columnNames = {"user_id", "comment_id", "type"}) - }) +@Table(name = "reactions") public class Reaction { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/openisle/service/ReactionService.java b/src/main/java/com/openisle/service/ReactionService.java index cfbea0c33..2b90670af 100644 --- a/src/main/java/com/openisle/service/ReactionService.java +++ b/src/main/java/com/openisle/service/ReactionService.java @@ -28,11 +28,6 @@ public class ReactionService { .orElseThrow(() -> new IllegalArgumentException("User not found")); Post post = postRepository.findById(postId) .orElseThrow(() -> new IllegalArgumentException("Post not found")); - java.util.Optional existing = reactionRepository.findByUserAndPostAndType(user, post, type); - if (existing.isPresent()) { - reactionRepository.delete(existing.get()); - return null; - } Reaction reaction = new Reaction(); reaction.setUser(user); reaction.setPost(post); @@ -49,11 +44,6 @@ public class ReactionService { .orElseThrow(() -> new IllegalArgumentException("User not found")); Comment comment = commentRepository.findById(commentId) .orElseThrow(() -> new IllegalArgumentException("Comment not found")); - java.util.Optional existing = reactionRepository.findByUserAndCommentAndType(user, comment, type); - if (existing.isPresent()) { - reactionRepository.delete(existing.get()); - return null; - } Reaction reaction = new Reaction(); reaction.setUser(user); reaction.setComment(comment);