Skip to content

Commit

Permalink
fix: 마지막 미션 완료 시 행성 상태가 바로 업데이트되지 않는 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
yun8565 committed Nov 29, 2024
1 parent 8c49c91 commit 47fde4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.spaceme.mission.repository.MissionRepository;
import com.spaceme.planet.domain.Planet;
import com.spaceme.planet.repository.PlanetRepository;
import com.spaceme.planet.service.PlanetScheduler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -25,6 +26,7 @@ public class MissionService {

private final MissionRepository missionRepository;
private final PlanetRepository planetRepository;
private final PlanetScheduler planetScheduler;

public List<MissionResponse> findAllMissionByPlanetId(Long planetId) {
return missionRepository.findAllByPlanetId(planetId).stream()
Expand Down Expand Up @@ -65,6 +67,9 @@ public void setMissionStatusAsClear(Long userId, Long missionId) {
.orElseThrow(() -> new NotFoundException("미션을 찾을 수 없습니다."));

mission.updateStatus(CLEAR);
missionRepository.save(mission);

planetScheduler.checkPlanetAcquirable();
}

public void validateMission(Long userId, Long missionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ public void checkPlanetStatusDaily() {
@Scheduled(cron = "0 0 0 * * ?")
public void checkPlanetAcquirable() {
planetRepository.findByStatus(ON_PROGRESS).forEach(planet -> {
LocalDate lastDate = missionRepository.findLastByPlanetId(planet.getId())
.orElseThrow(() -> new NotFoundException("미션을 찾을 수 없습니다."))
.getDate();
Mission lastMission = missionRepository.findLastByPlanetId(planet.getId())
.orElseThrow(() -> new NotFoundException("미션을 찾을 수 없습니다."));

if(missionRepository.findAllByDate(lastDate).stream()
.allMatch(mission -> mission.getStatus().isPast())) {
if(lastMission.getStatus().isPast()) {
planet.updateStatus(ACQUIRABLE);
log.info("행성 ID : {} 획득 가능 상태로 업데이트 완료", planet.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import java.util.List;
import java.util.Optional;

import static com.spaceme.common.domain.Status.ACQUIRABLE;
import static com.spaceme.common.domain.Status.CLEAR;
import static com.spaceme.common.domain.Status.*;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -70,12 +69,11 @@ public RatioResponse acquirePlanet(Long userId, Long planetId) {

double probability = getProbability(planetId);
boolean hasAcquired = probabilityGenerator.acquirePlanetTheme(probability);
Planet planet = planetRepository.findById(planetId)
.orElseThrow(() -> new NotFoundException("행성을 찾을 수 없습니다."));

planet.updateStatus(hasAcquired ? CLEAR : FAILED);

if(hasAcquired) {
Planet planet = planetRepository.findById(planetId)
.orElseThrow(() -> new NotFoundException("행성을 찾을 수 없습니다."));
planet.updateStatus(CLEAR);
}
return RatioResponse.of(hasAcquired, (int)(probability*100));
}

Expand Down

0 comments on commit 47fde4c

Please sign in to comment.