From 53ce2dfa9671776d77e909606ab49fc9028feffe Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Fri, 11 Jul 2025 13:31:26 +0800 Subject: [PATCH] feat: add new reaction types and enforce single reaction per type --- open-isle-cli/src/components/ReactionsGroup.vue | 10 +++++++++- open-isle-cli/src/views/MessagePageView.vue | 10 +++++++++- src/main/java/com/openisle/model/Reaction.java | 6 +++++- src/main/java/com/openisle/model/ReactionType.java | 10 +++++++++- .../java/com/openisle/service/ReactionService.java | 12 ++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/open-isle-cli/src/components/ReactionsGroup.vue b/open-isle-cli/src/components/ReactionsGroup.vue index 24c850f73..0e26e02db 100644 --- a/open-isle-cli/src/components/ReactionsGroup.vue +++ b/open-isle-cli/src/components/ReactionsGroup.vue @@ -58,7 +58,15 @@ const iconMap = { LIKE: '❤️', DISLIKE: '👎', RECOMMEND: '👏', - ANGRY: '😡' + ANGRY: '😡', + FLUSHED: '😳', + STAR_STRUCK: '🤩', + ROFL: '🤣', + HOLDING_BACK_TEARS: '🥹', + MIND_BLOWN: '🤯', + POOP: '💩', + CLOWN: '🤡', + SKULL: '☠️' } export default { diff --git a/open-isle-cli/src/views/MessagePageView.vue b/open-isle-cli/src/views/MessagePageView.vue index 4eddcfc6d..9aab07ea7 100644 --- a/open-isle-cli/src/views/MessagePageView.vue +++ b/open-isle-cli/src/views/MessagePageView.vue @@ -153,7 +153,15 @@ export default { LIKE: '❤️', DISLIKE: '👎', RECOMMEND: '👏', - ANGRY: '😡' + ANGRY: '😡', + FLUSHED: '😳', + STAR_STRUCK: '🤩', + ROFL: '🤣', + HOLDING_BACK_TEARS: '🥹', + MIND_BLOWN: '🤯', + POOP: '💩', + CLOWN: '🤡', + SKULL: '☠️' } const sanitizeDescription = (text) => { diff --git a/src/main/java/com/openisle/model/Reaction.java b/src/main/java/com/openisle/model/Reaction.java index b51e92759..9fb71d8c1 100644 --- a/src/main/java/com/openisle/model/Reaction.java +++ b/src/main/java/com/openisle/model/Reaction.java @@ -12,7 +12,11 @@ import lombok.Setter; @Getter @Setter @NoArgsConstructor -@Table(name = "reactions") +@Table(name = "reactions", + uniqueConstraints = { + @UniqueConstraint(columnNames = {"user_id", "post_id", "type"}), + @UniqueConstraint(columnNames = {"user_id", "comment_id", "type"}) + }) public class Reaction { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/openisle/model/ReactionType.java b/src/main/java/com/openisle/model/ReactionType.java index 442546638..34ab2c1af 100644 --- a/src/main/java/com/openisle/model/ReactionType.java +++ b/src/main/java/com/openisle/model/ReactionType.java @@ -7,5 +7,13 @@ public enum ReactionType { LIKE, DISLIKE, RECOMMEND, - ANGRY + ANGRY, + FLUSHED, + STAR_STRUCK, + ROFL, + HOLDING_BACK_TEARS, + MIND_BLOWN, + POOP, + CLOWN, + SKULL } diff --git a/src/main/java/com/openisle/service/ReactionService.java b/src/main/java/com/openisle/service/ReactionService.java index 74dccb0fd..b51d418c0 100644 --- a/src/main/java/com/openisle/service/ReactionService.java +++ b/src/main/java/com/openisle/service/ReactionService.java @@ -28,6 +28,12 @@ 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); @@ -44,6 +50,12 @@ 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);