From 461d34dfe7be5724d300b9af18cc7569c02516e4 Mon Sep 17 00:00:00 2001 From: swonny Date: Sat, 4 Nov 2023 18:49:02 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EC=A0=80=EC=9E=A5=20=EC=8B=9C=20=EC=97=AC?= =?UTF-8?q?=EB=9F=AC=20=EA=B0=9C=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/application/LastReadMessageLogService.java | 6 ++++-- .../chat/domain/repository/ReadMessageLogRepository.java | 5 +++-- .../persistence/ReadMessageLogRepositoryImpl.java | 9 +++++---- .../fixture/LastReadMessageLogServiceFixture.java | 4 ++-- ...QuerydslChatRoomAndMessageAndImageRepositoryTest.java | 3 +-- .../persistence/ReadMessageLogRepositoryImplTest.java | 3 ++- .../fixture/ReadMessageLogRepositoryFixture.java | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/LastReadMessageLogService.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/LastReadMessageLogService.java index 6c1ee8385..abba0d301 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/LastReadMessageLogService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/LastReadMessageLogService.java @@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @Transactional(readOnly = true) @RequiredArgsConstructor @@ -26,8 +28,7 @@ public void create(final CreateReadMessageLogEvent createReadMessageLogEvent) { final ReadMessageLog buyerReadMessageLog = new ReadMessageLog(chatRoom, buyer); final ReadMessageLog sellerReadMessageLog = new ReadMessageLog(chatRoom, seller); - readMessageLogRepository.save(buyerReadMessageLog); - readMessageLogRepository.save(sellerReadMessageLog); + readMessageLogRepository.saveAll(List.of(buyerReadMessageLog, sellerReadMessageLog)); } @Transactional @@ -39,6 +40,7 @@ public void update(final UpdateReadMessageLogEvent updateReadMessageLogEvent) { new ReadMessageLogNotFoundException( "메시지 조회 로그가 존재하지 않습니다." )); + messageLog.updateLastReadMessage(updateReadMessageLogEvent.lastReadMessage().getId()); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/domain/repository/ReadMessageLogRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/domain/repository/ReadMessageLogRepository.java index 7336fa340..0da187e3a 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/domain/repository/ReadMessageLogRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/domain/repository/ReadMessageLogRepository.java @@ -2,11 +2,12 @@ import com.ddang.ddang.chat.domain.ReadMessageLog; +import java.util.List; import java.util.Optional; public interface ReadMessageLogRepository { - ReadMessageLog save(final ReadMessageLog readMessageLog); - Optional findBy(final Long readerId, final Long chatRoomId); + + List saveAll(List readMessageLogs); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImpl.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImpl.java index bab34022f..dceecf3ed 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImpl.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImpl.java @@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository @@ -14,12 +15,12 @@ public class ReadMessageLogRepositoryImpl implements ReadMessageLogRepository { private final JpaReadMessageLogRepository jpaReadMessageLogRepository; @Override - public ReadMessageLog save(final ReadMessageLog readMessageLog) { - return jpaReadMessageLogRepository.save(readMessageLog); + public Optional findBy(final Long readerId, final Long chatRoomId) { + return jpaReadMessageLogRepository.findLastReadMessageByUserIdAndChatRoomId(readerId, chatRoomId); } @Override - public Optional findBy(final Long readerId, final Long chatRoomId) { - return jpaReadMessageLogRepository.findLastReadMessageByUserIdAndChatRoomId(readerId, chatRoomId); + public List saveAll(final List readMessageLogs) { + return jpaReadMessageLogRepository.saveAll(readMessageLogs); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/application/fixture/LastReadMessageLogServiceFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/application/fixture/LastReadMessageLogServiceFixture.java index 928d695a7..737969fd0 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/application/fixture/LastReadMessageLogServiceFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/application/fixture/LastReadMessageLogServiceFixture.java @@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import java.time.LocalDateTime; +import java.util.List; @SuppressWarnings("NonAsciiCharacters") public class LastReadMessageLogServiceFixture { @@ -174,8 +175,7 @@ void fixtureSetUp( final ReadMessageLog 메시지_로그_업데이트용_로그_판매자 = new ReadMessageLog(메시지_로그_업데이트용_채팅방, 메시지_로그_업데이트용_발신자_겸_판매자); final ReadMessageLog 메시지_로그_업데이트용_로그_구매자 = new ReadMessageLog(메시지_로그_업데이트용_채팅방, 메시지_로그_업데이트용_입찰자); - readMessageLogRepository.save(메시지_로그_업데이트용_로그_판매자); - readMessageLogRepository.save(메시지_로그_업데이트용_로그_구매자); + readMessageLogRepository.saveAll(List.of(메시지_로그_업데이트용_로그_판매자, 메시지_로그_업데이트용_로그_구매자)); 메시지_로그_업데이트용_이벤트 = new UpdateReadMessageLogEvent(메시지_로그_업데이트용_발신자_겸_판매자, 메시지_로그_업데이트용_채팅방, 메시지_로그_업데이트용_마지막_조회_메시지); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepositoryTest.java index 89ead8823..fc55b97c7 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepositoryTest.java @@ -45,8 +45,7 @@ void setUp( @Test void 사용자가_읽지_않은_메시지_개수를_반환한다() { // given - readMessageLogRepository.save(new ReadMessageLog(메리_엔초_채팅방, 엔초)); - readMessageLogRepository.save(new ReadMessageLog(메리_엔초_채팅방, 메리)); + readMessageLogRepository.saveAll(List.of(new ReadMessageLog(메리_엔초_채팅방, 메리), new ReadMessageLog(메리_엔초_채팅방, 엔초))); // when messageRepository.save(메리가_엔초에게_3시에_보낸_쪽지1); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImplTest.java index 758d1c064..ad254efd8 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImplTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/ReadMessageLogRepositoryImplTest.java @@ -14,6 +14,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; +import java.util.List; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; @@ -34,7 +35,7 @@ void setUp(@Autowired final JpaReadMessageLogRepository jpaReadMessageLogReposit @Test void 마지막_읽은_메시지를_저장한다() { // given - final ReadMessageLog actual = readMessageLogRepository.save(다섯_번째_메시지까지_읽은_메시지_로그); + final ReadMessageLog actual = readMessageLogRepository.saveAll(List.of(다섯_번째_메시지까지_읽은_메시지_로그)).get(0); // then assertThat(actual.getId()).isPositive(); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ReadMessageLogRepositoryFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ReadMessageLogRepositoryFixture.java index 71a594bad..02c48e537 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ReadMessageLogRepositoryFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ReadMessageLogRepositoryFixture.java @@ -144,6 +144,6 @@ void fixtureSetUp( final ReadMessageLog 메리_엔초_채팅방의_메리_메시지_조회_로그 = new ReadMessageLog(메리_엔초_채팅방, 메리); 메리_엔초_채팅방의_메리_메시지_조회_로그.updateLastReadMessage(다섯_번째_메시지.getId()); - readMessageLogRepository.save(메리_엔초_채팅방의_메리_메시지_조회_로그); + readMessageLogRepository.saveAll(List.of(메리_엔초_채팅방의_메리_메시지_조회_로그)); } }