mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 16:21:15 +08:00
fix post deletion cascade
This commit is contained in:
@@ -10,4 +10,5 @@ import java.util.Optional;
|
||||
public interface PostReadRepository extends JpaRepository<PostRead, Long> {
|
||||
Optional<PostRead> findByUserAndPost(User user, Post post);
|
||||
long countByUser(User user);
|
||||
void deleteByPost(Post post);
|
||||
}
|
||||
|
||||
@@ -41,4 +41,9 @@ public class PostReadService {
|
||||
.orElseThrow(() -> new IllegalArgumentException("User not found"));
|
||||
return postReadRepository.countByUser(user);
|
||||
}
|
||||
|
||||
@org.springframework.transaction.annotation.Transactional
|
||||
public void deleteByPost(Post post) {
|
||||
postReadRepository.deleteByPost(post);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,6 +360,7 @@ public class PostService {
|
||||
reactionRepository.findByPost(post).forEach(reactionRepository::delete);
|
||||
postSubscriptionRepository.findByPost(post).forEach(postSubscriptionRepository::delete);
|
||||
notificationRepository.deleteAll(notificationRepository.findByPost(post));
|
||||
postReadService.deleteByPost(post);
|
||||
postRepository.delete(post);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user