mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-05 17:47:36 +08:00
Implement reaction panel with backend support
This commit is contained in:
@@ -28,8 +28,12 @@ public class ReactionService {
|
||||
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
||||
Post post = postRepository.findById(postId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Post not found"));
|
||||
Reaction reaction = reactionRepository.findByUserAndPost(user, post)
|
||||
.orElseGet(Reaction::new);
|
||||
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);
|
||||
reaction.setType(type);
|
||||
@@ -45,8 +49,12 @@ public class ReactionService {
|
||||
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
||||
Comment comment = commentRepository.findById(commentId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Comment not found"));
|
||||
Reaction reaction = reactionRepository.findByUserAndComment(user, comment)
|
||||
.orElseGet(Reaction::new);
|
||||
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);
|
||||
reaction.setPost(null);
|
||||
|
||||
Reference in New Issue
Block a user