Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ private List<Calendar> cacheAllCalendarResponse() {
}

private Optional<Calendar> getRecentCalendar(List<Calendar> calendars) {
return calendars.stream()
.filter(calendar -> !calendar.getStartDate().isBefore(CurrentDate.now))
.findFirst();
List<Calendar> sorted = calendars.stream()
.sorted(Comparator.comparing(Calendar::getStartDate)
.thenComparing(Calendar::getEndDate))
.toList();

return sorted.stream()
.filter(calendar -> !calendar.getStartDate().isBefore(CurrentDate.now()))
.findFirst();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

특별히 스트림을 분리한 이유가 있으실까요?
없으시다면 가독성이나 성능 측면에서 하나의 스트림으로 처리하는 것이 좋다고 보여지는데, 의견이 궁금합니다!

Suggested change
List<Calendar> sorted = calendars.stream()
.sorted(Comparator.comparing(Calendar::getStartDate)
.thenComparing(Calendar::getEndDate))
.toList();
return sorted.stream()
.filter(calendar -> !calendar.getStartDate().isBefore(CurrentDate.now()))
.findFirst();
return calendars.stream()
.sorted(Comparator.comparing(Calendar::getStartDate)
.thenComparing(Calendar::getEndDate))
.filter(calendar -> !calendar.getStartDate().isBefore(CurrentDate.now()))
.findFirst();

Copy link
Collaborator Author

@hyerinhwang-sailin hyerinhwang-sailin Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 로컬에서 로그 찍어보려고 분리했던걸 다시 안 합쳐뒀네요 체크 감사합니다 합쳐두겠습니다!

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void handleUserWithdrawEvent(final UserWithdrawEvent event) {

public boolean isExistTodayFortune(final Long userId) {
return userFortuneRepository.findByUserId(userId)
.map(userFortune -> userFortune.getCheckedAt().equals(CurrentDate.now))
.map(userFortune -> userFortune.getCheckedAt().equals(CurrentDate.now()))
.orElse(false);
}
}
13 changes: 0 additions & 13 deletions src/main/java/org/sopt/app/application/user/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.sopt.app.application.user;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -88,18 +87,6 @@ public boolean isUserExist(Long userId) {
return userRepository.existsById(userId);
}

public Long getDuration(Long myGeneration, Long currentGeneration) {
long monthsBetweenGenerations = (currentGeneration - myGeneration) * 6;
LocalDate now = LocalDate.now();
int currentMonth = now.getMonthValue();
int startMonth = (currentGeneration % 2 == 0) ? 3 : 9;
int monthsSinceStart = currentMonth - startMonth;
if (monthsSinceStart < 0) {
monthsSinceStart += 12;
}
return monthsBetweenGenerations + monthsSinceStart;
}

public List<String> getIcons(IconType iconType) {
return iconRepository.findAllByIconType(iconType).stream()
.map(Icons::getIconUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static LocalDate getGenerationStartDate(Long generation) {
}

private static int getMonthDifferenceFromNow(LocalDate startDate) {
Period period = Period.between(startDate, CurrentDate.now);
Period period = Period.between(startDate, CurrentDate.now());
return period.getYears() * 12 + period.getMonths() + 1;
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/sopt/app/common/utils/CurrentDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@

@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public class CurrentDate {
public static final LocalDate now = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDate();
public static LocalDate now() {
return ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDate();
}
Comment on lines +8 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와우 static final이어서 한번 지정된 날짜가 변경되지 않았겠군요 ... 찾느라 고생하셨습니다 ! ㅠㅠ

}
4 changes: 0 additions & 4 deletions src/main/java/org/sopt/app/facade/AuthFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ public PlaygroundProfile getUserDetails(User user) {
return playgroundAuthService.getPlayGroundProfile(user.getPlaygroundToken());
}

public Long getDuration(Long myGeneration, Long generation) {
return userService.getDuration(myGeneration, generation);
}

public List<String> getIcons(IconType iconType) {
return userService.getIcons(iconType);
}
Expand Down