From 075b57e9db38341ef739c1d2f6b3594c302c0dda Mon Sep 17 00:00:00 2001 From: Pepe Ronin Date: Sun, 1 Jun 2025 00:54:36 +0300 Subject: [PATCH 1/3] fix comment update timestamp in server response --- .../explorewithme/main/service/CommentServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java b/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java index c3fa85c..c697c94 100644 --- a/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java +++ b/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java @@ -122,6 +122,6 @@ public CommentDto updateUserComment(Long userId, Long commentId, UpdateCommentDt existedComment.setText(updateCommentDto.getText()); existedComment.setEdited(true); - return commentMapper.toDto(commentRepository.save(existedComment)); + return commentMapper.toDto(commentRepository.saveAndFlush(existedComment)); } } From d61b07ebb02e91bdf4a375564be34a5324b5ba49 Mon Sep 17 00:00:00 2001 From: Pepe Ronin Date: Sun, 1 Jun 2025 00:54:51 +0300 Subject: [PATCH 2/3] might as well --- .../explorewithme/main/service/CommentServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java b/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java index c697c94..02e3c0c 100644 --- a/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java +++ b/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java @@ -111,7 +111,7 @@ public CommentDto updateUserComment(Long userId, Long commentId, UpdateCommentDt throw new EntityNotFoundException("Искомый комментарий с id " + commentId + " пользователя с id " + userId + "не найден"); } - if (existedComment.isDeleted() == true) { + if (existedComment.isDeleted()) { throw new BusinessRuleViolationException("Редактирование невозможно. Комментарий удален"); } From 57f7be79c8dd37057b3eaba3cbdfc83cee4d3141 Mon Sep 17 00:00:00 2001 From: Pepe Ronin Date: Sun, 1 Jun 2025 01:27:48 +0300 Subject: [PATCH 3/3] update tests to interact with correct repository method --- .../explorewithme/main/service/CommentServiceImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java b/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java index 78394c9..05f2565 100644 --- a/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java +++ b/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java @@ -155,13 +155,13 @@ void updateUserComment_shouldUpdateCommentAndReturnDto() { when(commentRepository.findById(commentId)).thenReturn(Optional.of(comment)); when(commentMapper.toDto(any(Comment.class))).thenReturn(expectedDto); - when(commentRepository.save(any(Comment.class))).thenAnswer(invocation -> invocation.getArgument(0)); + when(commentRepository.saveAndFlush(any(Comment.class))).thenAnswer(invocation -> invocation.getArgument(0)); CommentDto result = commentService.updateUserComment(userId, commentId, updateCommentDto); Assertions.assertEquals("Updated text", result.getText()); Assertions.assertTrue(comment.isEdited()); - verify(commentRepository).save(comment); + verify(commentRepository).saveAndFlush(comment); } @Test