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
Expand Up @@ -14,9 +14,7 @@
* DATE AUTHOR DESCRIPTION
* ---------------------------------------------------------------------------------------------------------------------
* 26. 3. 24. loadingKKamo21 Initial creation
* 26. 4. 2. loadingKKamo21 findByIdAndIsSuccessFalse 제거, findById 로 통합
*/
public interface VisitingHistoryRepository extends JpaRepository<VisitingHistory, Long>, VisitingHistoryRepositoryCustom {

Optional<VisitingHistory> findByIdAndIsSuccessFalse(Long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private void validateEndTime(final LocalDateTime startTime, final LocalDateTime

/**
* 탐색 종료 (종료 시간 설정 및 성공/실패 자동 판별)
* 시스템이 자동으로 성공/실패를 판정 (열차 출발 전 도착 여부)
*
* @param endTime 탐색 종료 시간
*/
Expand All @@ -301,6 +302,20 @@ public void endJourney(final LocalDateTime endTime) {
this.isSuccess = !endTime.isAfter(this.trainDepartureTime);
}

/**
* 여정 종료 (사용자 선언 기반 성공/실패)
* 사용자의 isCompleted 선언에 따라 무조건 성공/실패로 처리
*
* @param endTime 탐색 종료 시간
* @param success 사용자 선언 성공 여부 (true = 성공, false = 실패)
*/
public void endJourney(final LocalDateTime endTime, final boolean success) {
validateEndTime(this.startTime, endTime);
this.endTime = endTime;
this.totalDurationMinutes = calculateDurationMinutes(this.startTime, endTime);
this.isSuccess = success;
}

/**
* 여정 포기 (사용자가 중도 포기)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public VisitingHistoryDetailResponse createNewJourney(final UUID userId, final J
public VisitingHistoryDetailResponse endJourney(final UUID userId,
final Long historyId,
final JourneyEndRequest dto) {
VisitingHistory visitingHistory = visitingHistoryRepository.findByIdAndIsSuccessFalse(historyId)
VisitingHistory visitingHistory = visitingHistoryRepository.findById(historyId)
.orElseThrow(
() -> new GlobalException(HISTORY_NOT_FOUND)
);
Expand All @@ -130,18 +130,15 @@ public VisitingHistoryDetailResponse endJourney(final UUID userId,

visitingHistory.validateEndable();

if (dto.getIsCompleted()) {
visitingHistory.endJourney(LocalDateTime.now(clock));

if (visitingHistory.isSuccess()) {
User user = visitingHistory.getUser();
Station station = visitingHistory.getStation();
int durationMinutes = visitingHistory.getTotalDurationMinutes();
if (Boolean.TRUE.equals(dto.getIsCompleted())) {
visitingHistory.endJourney(LocalDateTime.now(clock), true);

user.addVisitHistory(durationMinutes, true);
User user = visitingHistory.getUser();
Station station = visitingHistory.getStation();
int durationMinutes = visitingHistory.getTotalDurationMinutes();

updateFavoriteVisitCount(user, station, durationMinutes);
}
user.addVisitHistory(durationMinutes, true);
updateFavoriteVisitCount(user, station, durationMinutes);
} else
visitingHistory.abandonJourney();

Expand Down