Allow multiple reactions per user

This commit is contained in:
Tim
2025-07-09 18:35:59 +08:00
parent ccd0c817f6
commit 4e12b622ce
2 changed files with 1 additions and 15 deletions

View File

@@ -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)

View File

@@ -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<Reaction> 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<Reaction> 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);