Skip to content

Commit

Permalink
Merge pull request #325 from depromeet/fix/#324-public-record-alarm
Browse files Browse the repository at this point in the history
fix: 알림 페이지, 기록에 대한 예외 처리
  • Loading branch information
char-yb authored Nov 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 2779921 + a1fe9c3 commit ac1871b
Showing 4 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ private List<FcmNotification> getNotifications(

try {
LocalDateTime cursorDate = LocalDateTime.parse(cursor, DATE_FORMATTER);
return notificationRepository.findByMemberIdAndCreatedAtLessThanEqual(
return notificationRepository.findMissionRecordNotificationByMemberPaging(
memberId, cursorDate, pageable);
} catch (DateTimeParseException e) {
throw new CustomException(ErrorCode.INVALID_CURSOR_DATE_FORMAT);
Original file line number Diff line number Diff line change
@@ -12,12 +12,10 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface FcmNotificationRepository extends JpaRepository<FcmNotification, Long> {
public interface FcmNotificationRepository
extends JpaRepository<FcmNotification, Long>, FcmNotificationRepositoryCustom {
List<FcmNotification> findByMemberId(Long memberId, Pageable pageable);

List<FcmNotification> findByMemberIdAndCreatedAtLessThanEqual(
Long memberId, LocalDateTime cursorDate, Pageable pageable);

Optional<FcmNotification> findByIdAndMember(Long id, Member member);

boolean existsByCreatedAtLessThan(LocalDateTime createdAt);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.depromeet.stonebed.domain.fcm.dao;

import com.depromeet.stonebed.domain.fcm.domain.FcmNotification;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.domain.Pageable;

public interface FcmNotificationRepositoryCustom {
List<FcmNotification> findMissionRecordNotificationByMemberPaging(
Long memberId, LocalDateTime cursorDate, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.depromeet.stonebed.domain.fcm.dao;

import static com.depromeet.stonebed.domain.fcm.domain.QFcmNotification.*;
import static com.depromeet.stonebed.domain.missionRecord.domain.QMissionRecord.*;

import com.depromeet.stonebed.domain.fcm.domain.FcmNotification;
import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecordDisplay;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;

@RequiredArgsConstructor
public class FcmNotificationRepositoryImpl implements FcmNotificationRepositoryCustom {
private final JPAQueryFactory jpaQueryFactory;

@Override
public List<FcmNotification> findMissionRecordNotificationByMemberPaging(
Long memberId, LocalDateTime cursorDate, Pageable pageable) {
return jpaQueryFactory
.select(fcmNotification)
.from(fcmNotification)
.innerJoin(fcmNotification.member)
.on(fcmNotification.member.id.eq(memberId))
.innerJoin(missionRecord)
.on(fcmNotification.targetId.eq(missionRecord.id))
.where(
fcmNotification
.createdAt
.loe(cursorDate)
.and(missionRecord.display.eq(MissionRecordDisplay.PUBLIC)))
.orderBy(fcmNotification.createdAt.desc())
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.fetch();
}
}

0 comments on commit ac1871b

Please sign in to comment.