mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-12 05:37:29 +08:00
Merge pull request #991 from nagisa77/codex/fix-foreign-key-constraint-error-on-deletepost-mrgsx4
Delete post change logs before removing posts
This commit is contained in:
@@ -8,4 +8,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface PostChangeLogRepository extends JpaRepository<PostChangeLog, Long> {
|
public interface PostChangeLogRepository extends JpaRepository<PostChangeLog, Long> {
|
||||||
List<PostChangeLog> findByPostOrderByCreatedAtAsc(Post post);
|
List<PostChangeLog> findByPostOrderByCreatedAtAsc(Post post);
|
||||||
|
|
||||||
|
void deleteByPost(Post post);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ public class PostChangeLogService {
|
|||||||
logRepository.save(log);
|
logRepository.save(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteLogsForPost(Post post) {
|
||||||
|
logRepository.deleteByPost(post);
|
||||||
|
}
|
||||||
|
|
||||||
public List<PostChangeLog> listLogs(Long postId) {
|
public List<PostChangeLog> listLogs(Long postId) {
|
||||||
Post post = postRepository.findById(postId)
|
Post post = postRepository.findById(postId)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
|
|||||||
@@ -888,6 +888,7 @@ public class PostService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String title = post.getTitle();
|
String title = post.getTitle();
|
||||||
|
postChangeLogService.deleteLogsForPost(post);
|
||||||
postRepository.delete(post);
|
postRepository.delete(post);
|
||||||
if (adminDeleting) {
|
if (adminDeleting) {
|
||||||
notificationService.createNotification(author, NotificationType.POST_DELETED,
|
notificationService.createNotification(author, NotificationType.POST_DELETED,
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ class PostServiceTest {
|
|||||||
|
|
||||||
verify(postReadService).deleteByPost(post);
|
verify(postReadService).deleteByPost(post);
|
||||||
verify(postRepo).delete(post);
|
verify(postRepo).delete(post);
|
||||||
|
verify(postChangeLogService).deleteLogsForPost(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user