Skip to content
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
@@ -1,7 +1,6 @@
package com.planetrush.planetrush.planet.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -264,35 +263,16 @@ public List<GetMainPlanetListDto> getMainPlanetList(Long memberId) {
.orElseThrow(() -> new MemberNotFoundException("Member not found with ID: " + memberId));
List<GetMainPlanetListVo> planetList = planetRepositoryCustom.getMainPlanetList(member);
return planetList.stream()
.map(this::convertToDto)
.map(vo -> GetMainPlanetListDto.builder()
.planetId(vo.getPlanetId())
.planetImgUrl(vo.getPlanetImgUrl())
.name(vo.getName())
.status(vo.getStatus())
.lastDay(planetValidator.checkLastDay(vo))
.build())
.toList();
}

/**
* 마지막 인증 날짜 혹은 행성 시작 날짜와 오늘 날짜를 비교해 lastDay 변수에 담아줍니다.
* @param vo GetMainPlanetListVo
* @return GetMainPlanetListDto
*/
private GetMainPlanetListDto convertToDto(GetMainPlanetListVo vo) {
LocalDate today = LocalDate.now();
LocalDateTime lastVerifyDate = vo.getLastVerifyDate();
LocalDate planetStartDate = vo.getPlanetStartDate();
boolean isLastDay = false;
long daysBetween = ChronoUnit.DAYS.between(planetStartDate, today);
isLastDay = daysBetween >= 2;
if (lastVerifyDate != null) {
daysBetween = ChronoUnit.DAYS.between(lastVerifyDate.toLocalDate(), today);
isLastDay = daysBetween >= 3;
}
return GetMainPlanetListDto.builder()
.planetId(vo.getPlanetId())
.planetImgUrl(vo.getPlanetImgUrl())
.name(vo.getName())
.status(vo.getStatus())
.lastDay(isLastDay)
.build();
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.planetrush.planetrush.planet.exception.ResidentOverflowException;
import com.planetrush.planetrush.planet.repository.ResidentRepository;
import com.planetrush.planetrush.planet.repository.custom.ResidentRepositoryCustom;
import com.planetrush.planetrush.planet.service.vo.GetMainPlanetListVo;

import lombok.RequiredArgsConstructor;

Expand All @@ -25,6 +26,9 @@ public class PlanetValidator {
private static final int MAX_RESIDENT_LIMIT = 9;
private static final int MAX_CHALLENGE_START_OFFSET = 14;

private static final int LAST_DAY_FROM_PLANET_START_DAYS = 2;
private static final int LAST_DAY_AFTER_VERIFY_DAYS = 3;

/**
* 가입 가능한 최대 챌린지 수를 초과하는지 검사합니다.
* @param member
Expand Down Expand Up @@ -59,4 +63,26 @@ public void checkStartDate(LocalDate startDate) {
}
}

/**
* 마지막 인증 날짜 혹은 행성 시작 날짜와 오늘 날짜를 비교해 결과를 반환합니다.
* @param vo GetMainPlanetListVo
* @return 행성에서 탈퇴 당하기 직전인지 여부
*/
public boolean checkLastDay(GetMainPlanetListVo vo) {
LocalDate today = LocalDate.now();
if (vo.getLastVerifyDate() != null) {
return isLastDayAfterVerify(vo.getLastVerifyDate().toLocalDate(), today);
}
return isLastDayFromPlanetStart(vo.getPlanetStartDate(), today);
}

private boolean isLastDayFromPlanetStart(LocalDate planetStartDate, LocalDate today) {
long daysPassed = ChronoUnit.DAYS.between(planetStartDate, today);
return daysPassed >= LAST_DAY_FROM_PLANET_START_DAYS;
}

private boolean isLastDayAfterVerify(LocalDate lastVerifyDate, LocalDate today) {
long daysPassed = ChronoUnit.DAYS.between(lastVerifyDate, today);
return daysPassed >= LAST_DAY_AFTER_VERIFY_DAYS;
}
}
Loading