Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.2.3 #328

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading