Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ private List<Calendar> cacheAllCalendarResponse() {

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

@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