Skip to content

Commit

Permalink
fix: 생일자가 없는 경우는 푸시알림 보내지 않도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hocaron committed Aug 14, 2024
1 parent 48d9514 commit cf929a2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.domain.Pageable;

import java.time.LocalDate;
import java.time.MonthDay;
import java.util.List;

import static kr.mashup.branding.repository.member.MemberRepositoryCustomImpl.MemberScoreQueryResult;
Expand All @@ -23,5 +24,5 @@ public interface MemberRepositoryCustom {

List<Member> findAllActiveByGeneration(Generation generation);

List<Member> retrieveByBirthDate(Generation generation, LocalDate birthDate);
List<Member> retrieveByBirthDate(Generation generation, MonthDay monthDay);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.data.domain.Sort;

import java.time.LocalDate;
import java.time.MonthDay;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -148,12 +149,15 @@ public List<Member> findAllActiveByGeneration(Generation generation) {
}

@Override
public List<Member> retrieveByBirthDate(Generation generation, LocalDate birthDate) {
public List<Member> retrieveByBirthDate(Generation generation, MonthDay monthDay) {
return queryFactory
.selectFrom(member)
.innerJoin(memberProfile).on(memberProfile.memberId.eq(member.id))
.innerJoin(memberGeneration).on(memberGeneration.generation.eq(generation))
.where(memberProfile.birthDate.eq(birthDate))
.innerJoin(memberGeneration).on(memberGeneration.member.eq(member))
.where(
memberProfile.birthDate.month().eq(monthDay.getMonthValue())
.and(memberProfile.birthDate.dayOfMonth().eq(monthDay.getDayOfMonth()))
)
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public List<MemberBirthdayDto> findByBirthDateBetween(MonthDay startDate, MonthD

public boolean isBirthdayToday(long memberId) {
return memberProfileRepository.findByMemberId(memberId)
.filter(memberProfile -> MonthDay.from(LocalDate.now()).equals(MonthDay.from(memberProfile.getBirthDate())))
.filter(memberProfile -> MonthDay.now().equals(MonthDay.from(memberProfile.getBirthDate())))
.isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.MonthDay;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -349,14 +350,19 @@ public MemberGeneration getCurrentMemberGeneration(Member member) {

@Transactional(readOnly = true)
public List<Member> getAllByBirthdayRecipient(Generation generation) {
return memberRepository.retrieveByBirthDate(generation, LocalDate.now());
return memberRepository.retrieveByBirthDate(generation, MonthDay.now());
}

@Transactional(readOnly = true)
public List<Member> getAllByBirthdaySender(Generation generation) {

// 생일자가 없는 경우는 푸시 알림을 보내지 않음
List<Member> recipients = memberRepository.retrieveByBirthDate(generation, MonthDay.now());
if (recipients.isEmpty()) {
return List.of();
}

List<Member> senders = memberRepository.findAllActiveByGeneration(generation);
List<Member> recipients = memberRepository.retrieveByBirthDate(generation, LocalDate.now());
senders.removeAll(recipients);

return senders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public MemberBirthdaysResponse getUpcomingBirthdays(Long memberId, Integer days)
}

private Map<MonthDay, List<MemberBirthdayDto>> calculateUpcomingBirthdays(Member member, Integer days, Generation generation) {
MonthDay today = MonthDay.from(LocalDate.now());
MonthDay today = MonthDay.now();
MonthDay endDay = MonthDay.from(LocalDate.now().plusDays(days));
return memberProfileService.findByBirthDateBetween(today, endDay, generation)
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.time.LocalDate;
import java.time.MonthDay;
import java.util.Comparator;
import java.util.List;
Expand All @@ -25,7 +24,7 @@ public class MemberBirthdaysResponse {
public static MemberBirthdaysResponse of(boolean isBirthdayToday, Set<Long> sentMemberIds, Map<MonthDay, List<MemberBirthdayDto>> upcomingBirthdays) {
List<MemberBirthdayResponse> responses = createResponses(sentMemberIds, upcomingBirthdays);

MonthDay today = MonthDay.from(LocalDate.now());
MonthDay today = MonthDay.now();
MemberBirthdayResponse todayBirthday = extractTodayBirthday(today, responses);
List<MemberBirthdayResponse> sortedResponses = sortUpcomingBirthdays(today, responses);

Expand Down

0 comments on commit cf929a2

Please sign in to comment.