From c01bf4477aef9a4b0cec931db847307f87f4ff54 Mon Sep 17 00:00:00 2001 From: ybchar Date: Sat, 2 Nov 2024 22:54:00 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EC=95=8C=EB=A6=BC=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20where=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fcm/application/FcmNotificationService.java | 12 ++++-------- .../fcm/dao/FcmNotificationRepositoryImpl.java | 16 +++++++++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java b/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java index 17e111d..f4864a8 100644 --- a/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java +++ b/src/main/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationService.java @@ -101,12 +101,10 @@ private List convertToNotificationDto(List private List getNotifications( String cursor, Long memberId, Pageable pageable) { - if (cursor == null) { - return notificationRepository.findByMemberId(memberId, pageable); - } - try { - LocalDateTime cursorDate = LocalDateTime.parse(cursor, DATE_FORMATTER); + LocalDateTime cursorDate = null; + if (cursor != null) cursorDate = LocalDateTime.parse(cursor, DATE_FORMATTER); + return notificationRepository.findMissionRecordNotificationByMemberPaging( memberId, cursorDate, pageable); } catch (DateTimeParseException e) { @@ -115,9 +113,7 @@ private List getNotifications( } private String getNextCursor(List notifications) { - if (notifications.isEmpty()) { - return null; - } + if (notifications.isEmpty()) return null; FcmNotification lastNotification = notifications.get(notifications.size() - 1); diff --git a/src/main/java/com/depromeet/stonebed/domain/fcm/dao/FcmNotificationRepositoryImpl.java b/src/main/java/com/depromeet/stonebed/domain/fcm/dao/FcmNotificationRepositoryImpl.java index d25cdf7..17418c8 100644 --- a/src/main/java/com/depromeet/stonebed/domain/fcm/dao/FcmNotificationRepositoryImpl.java +++ b/src/main/java/com/depromeet/stonebed/domain/fcm/dao/FcmNotificationRepositoryImpl.java @@ -5,6 +5,7 @@ import com.depromeet.stonebed.domain.fcm.domain.FcmNotification; import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecordDisplay; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.time.LocalDateTime; import java.util.List; @@ -23,16 +24,21 @@ public List findMissionRecordNotificationByMemberPaging( .from(fcmNotification) .innerJoin(fcmNotification.member) .on(fcmNotification.member.id.eq(memberId)) - .innerJoin(missionRecord) + .leftJoin(missionRecord) .on(fcmNotification.targetId.eq(missionRecord.id)) .where( - fcmNotification - .createdAt - .loe(cursorDate) - .and(missionRecord.display.eq(MissionRecordDisplay.PUBLIC))) + loeCursorDate(cursorDate), + missionRecord + .display + .eq(MissionRecordDisplay.PUBLIC) + .or(fcmNotification.targetId.isNull())) .orderBy(fcmNotification.createdAt.desc()) .limit(pageable.getPageSize()) .offset(pageable.getOffset()) .fetch(); } + + private BooleanExpression loeCursorDate(LocalDateTime cursorDate) { + return cursorDate != null ? fcmNotification.createdAt.loe(cursorDate) : null; + } } From 3387549f79b7822550c60e78d85745e6ef4784b4 Mon Sep 17 00:00:00 2001 From: ybchar Date: Sat, 2 Nov 2024 23:11:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=95=8C=EB=A6=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/FcmNotificationServiceTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationServiceTest.java b/src/test/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationServiceTest.java index 225e11f..1be2f28 100644 --- a/src/test/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationServiceTest.java +++ b/src/test/java/com/depromeet/stonebed/domain/fcm/application/FcmNotificationServiceTest.java @@ -12,6 +12,7 @@ import com.depromeet.stonebed.domain.member.domain.Member; import com.depromeet.stonebed.domain.missionRecord.dao.MissionRecordRepository; import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecord; +import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecordDisplay; import com.depromeet.stonebed.global.error.ErrorCode; import com.depromeet.stonebed.global.error.exception.CustomException; import com.depromeet.stonebed.global.util.MemberUtil; @@ -69,13 +70,22 @@ public class FcmNotificationServiceTest extends FixtureMonkeySetUp { PageRequest.of(0, 10, Sort.by(Sort.Direction.DESC, "createdAt")); // 첫 번째 페이지, 10개씩 List notifications = List.of(fcmNotification); - when(notificationRepository.findByMemberId(eq(member.getId()), eq(pageable))) + when(notificationRepository.findMissionRecordNotificationByMemberPaging( + member.getId(), null, pageable)) .thenReturn(notifications); if (fcmNotification.getType() == FcmNotificationType.BOOSTER) { List missionRecords = - List.of(fixtureMonkey.giveMeOne(MissionRecord.class)); - when(missionRecordRepository.findByIdIn(anyList())).thenReturn(missionRecords); + List.of( + fixtureMonkey + .giveMeBuilder(MissionRecord.class) + .set("member", member) + .set("display", MissionRecordDisplay.PUBLIC) + .sample()); + + List targetIds = + notifications.stream().map(FcmNotification::getTargetId).toList(); + when(missionRecordRepository.findByIdIn(targetIds)).thenReturn(missionRecords); } // when @@ -84,7 +94,6 @@ public class FcmNotificationServiceTest extends FixtureMonkeySetUp { // then assertFalse(responses.list().isEmpty()); - verify(notificationRepository, times(1)).findByMemberId(eq(member.getId()), eq(pageable)); if (fcmNotification.getType() == FcmNotificationType.BOOSTER) { verify(missionRecordRepository, times(1)).findByIdIn(anyList());