Skip to content

Commit

Permalink
Merge pull request #327 from depromeet/fix/#324-public-record-alarm
Browse files Browse the repository at this point in the history
fix: 알림 리스트 페이지 where 조건 처리
  • Loading branch information
char-yb authored Nov 2, 2024
2 parents ac1871b + 3387549 commit 346cb82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ private List<FcmNotificationDto> convertToNotificationDto(List<FcmNotification>

private List<FcmNotification> 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) {
Expand All @@ -115,9 +113,7 @@ private List<FcmNotification> getNotifications(
}

private String getNextCursor(List<FcmNotification> notifications) {
if (notifications.isEmpty()) {
return null;
}
if (notifications.isEmpty()) return null;

FcmNotification lastNotification = notifications.get(notifications.size() - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,16 +24,21 @@ public List<FcmNotification> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,13 +70,22 @@ public class FcmNotificationServiceTest extends FixtureMonkeySetUp {
PageRequest.of(0, 10, Sort.by(Sort.Direction.DESC, "createdAt")); // 첫 번째 페이지, 10개씩
List<FcmNotification> 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<MissionRecord> 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<Long> targetIds =
notifications.stream().map(FcmNotification::getTargetId).toList();
when(missionRecordRepository.findByIdIn(targetIds)).thenReturn(missionRecords);
}

// when
Expand All @@ -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());
Expand Down

0 comments on commit 346cb82

Please sign in to comment.