feat: 处理添加表情偶现失败的问题

This commit is contained in:
tim
2025-08-03 20:12:44 +08:00
parent d70433ff93
commit 354cc7cd17
3 changed files with 6 additions and 4 deletions

View File

@@ -27,7 +27,6 @@ public class ReactionController {
} }
@PostMapping("/posts/{postId}/reactions") @PostMapping("/posts/{postId}/reactions")
@Transactional
public ResponseEntity<ReactionDto> reactToPost(@PathVariable Long postId, public ResponseEntity<ReactionDto> reactToPost(@PathVariable Long postId,
@RequestBody ReactionRequest req, @RequestBody ReactionRequest req,
Authentication auth) { Authentication auth) {
@@ -41,7 +40,6 @@ public class ReactionController {
} }
@PostMapping("/comments/{commentId}/reactions") @PostMapping("/comments/{commentId}/reactions")
@Transactional
public ResponseEntity<ReactionDto> reactToComment(@PathVariable Long commentId, public ResponseEntity<ReactionDto> reactToComment(@PathVariable Long commentId,
@RequestBody ReactionRequest req, @RequestBody ReactionRequest req,
Authentication auth) { Authentication auth) {

View File

@@ -70,6 +70,7 @@ public class CommentService {
return comment; return comment;
} }
@Transactional
public Comment addReply(String username, Long parentId, String content) { public Comment addReply(String username, Long parentId, String content) {
long recent = commentRepository.countByAuthorAfter(username, long recent = commentRepository.countByAuthorAfter(username,
java.time.LocalDateTime.now().minusMinutes(1)); java.time.LocalDateTime.now().minusMinutes(1));
@@ -154,7 +155,7 @@ public class CommentService {
return commentRepository.findLastCommentTime(post); return commentRepository.findLastCommentTime(post);
} }
@org.springframework.transaction.annotation.Transactional @Transactional
public void deleteComment(String username, Long id) { public void deleteComment(String username, Long id) {
User user = userRepository.findByUsername(username) User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
@@ -166,7 +167,7 @@ public class CommentService {
deleteCommentCascade(comment); deleteCommentCascade(comment);
} }
@org.springframework.transaction.annotation.Transactional @Transactional
public void deleteCommentCascade(Comment comment) { public void deleteCommentCascade(Comment comment) {
List<Comment> replies = commentRepository.findByParentOrderByCreatedAtAsc(comment); List<Comment> replies = commentRepository.findByParentOrderByCreatedAtAsc(comment);
for (Comment c : replies) { for (Comment c : replies) {

View File

@@ -15,6 +15,7 @@ import com.openisle.service.EmailSender;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@@ -29,6 +30,7 @@ public class ReactionService {
@Value("${app.website-url}") @Value("${app.website-url}")
private String websiteUrl; private String websiteUrl;
@Transactional
public Reaction reactToPost(String username, Long postId, ReactionType type) { public Reaction reactToPost(String username, Long postId, ReactionType type) {
User user = userRepository.findByUsername(username) User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
@@ -51,6 +53,7 @@ public class ReactionService {
return reaction; return reaction;
} }
@Transactional
public Reaction reactToComment(String username, Long commentId, ReactionType type) { public Reaction reactToComment(String username, Long commentId, ReactionType type) {
User user = userRepository.findByUsername(username) User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));