From 354cc7cd17890ade0f077c0616b1685b51f06bf9 Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 3 Aug 2025 20:12:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=A1=A8=E6=83=85=E5=81=B6=E7=8E=B0=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/openisle/controller/ReactionController.java | 2 -- .../src/main/java/com/openisle/service/CommentService.java | 5 +++-- .../src/main/java/com/openisle/service/ReactionService.java | 3 +++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/openisle/controller/ReactionController.java b/backend/src/main/java/com/openisle/controller/ReactionController.java index b7824a8ca..062fe313a 100644 --- a/backend/src/main/java/com/openisle/controller/ReactionController.java +++ b/backend/src/main/java/com/openisle/controller/ReactionController.java @@ -27,7 +27,6 @@ public class ReactionController { } @PostMapping("/posts/{postId}/reactions") - @Transactional public ResponseEntity reactToPost(@PathVariable Long postId, @RequestBody ReactionRequest req, Authentication auth) { @@ -41,7 +40,6 @@ public class ReactionController { } @PostMapping("/comments/{commentId}/reactions") - @Transactional public ResponseEntity reactToComment(@PathVariable Long commentId, @RequestBody ReactionRequest req, Authentication auth) { diff --git a/backend/src/main/java/com/openisle/service/CommentService.java b/backend/src/main/java/com/openisle/service/CommentService.java index 16820f4d0..70eb764f6 100644 --- a/backend/src/main/java/com/openisle/service/CommentService.java +++ b/backend/src/main/java/com/openisle/service/CommentService.java @@ -70,6 +70,7 @@ public class CommentService { return comment; } + @Transactional public Comment addReply(String username, Long parentId, String content) { long recent = commentRepository.countByAuthorAfter(username, java.time.LocalDateTime.now().minusMinutes(1)); @@ -154,7 +155,7 @@ public class CommentService { return commentRepository.findLastCommentTime(post); } - @org.springframework.transaction.annotation.Transactional + @Transactional public void deleteComment(String username, Long id) { User user = userRepository.findByUsername(username) .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found")); @@ -166,7 +167,7 @@ public class CommentService { deleteCommentCascade(comment); } - @org.springframework.transaction.annotation.Transactional + @Transactional public void deleteCommentCascade(Comment comment) { List replies = commentRepository.findByParentOrderByCreatedAtAsc(comment); for (Comment c : replies) { diff --git a/backend/src/main/java/com/openisle/service/ReactionService.java b/backend/src/main/java/com/openisle/service/ReactionService.java index 393de62b3..b6cda46f5 100644 --- a/backend/src/main/java/com/openisle/service/ReactionService.java +++ b/backend/src/main/java/com/openisle/service/ReactionService.java @@ -15,6 +15,7 @@ import com.openisle.service.EmailSender; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -29,6 +30,7 @@ public class ReactionService { @Value("${app.website-url}") private String websiteUrl; + @Transactional public Reaction reactToPost(String username, Long postId, ReactionType type) { User user = userRepository.findByUsername(username) .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found")); @@ -51,6 +53,7 @@ public class ReactionService { return reaction; } + @Transactional public Reaction reactToComment(String username, Long commentId, ReactionType type) { User user = userRepository.findByUsername(username) .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));