Skip to content

Commit

Permalink
refactor: 새롭게 수정된 일정을 벗어난 DayLog 삭제하는 로직 메서드 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
jjongwa committed Oct 4, 2023
1 parent d3ab7a8 commit f812570
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/src/main/java/hanglog/trip/service/TripService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hanglog.trip.dto.response.TripResponse;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.IntStream;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -158,10 +159,14 @@ private void addEmptyDayLogs(final Trip trip, final int currentPeriod, final int

private void removeRemainingDayLogs(final Trip trip, final int currentPeriod, final int requestPeriod) {
trip.getDayLogs().stream()
.filter(dayLog -> dayLog.getOrdinal() >= requestPeriod + 1 && dayLog.getOrdinal() <= currentPeriod)
.filter(getDayLogOutOfPeriod(currentPeriod, requestPeriod))
.forEach(trip::removeDayLog);
}

private Predicate<DayLog> getDayLogOutOfPeriod(final int currentPeriod, final int requestPeriod) {
return dayLog -> dayLog.getOrdinal() >= requestPeriod + 1 && dayLog.getOrdinal() <= currentPeriod;
}

public void delete(final Long tripId) {
final Trip trip = tripRepository.findById(tripId)
.orElseThrow(() -> new BadRequestException(NOT_FOUND_TRIP_ID));
Expand Down

0 comments on commit f812570

Please sign in to comment.