Skip to content

Commit 1e71e68

Browse files
committed
[NDGL-118] refactor: 코드래빗 리뷰 반영
- AddItineraryRequest 타입 수정 : String? -> Int? - handleAddPlace() : lastPlace가 null 일때 로직 추가 - placeRepository: 주석 제거 - toOpeningHours: day <= 0 체크 추가, java.time.* 의존성 -> kotlinx.datetime으로 수정 - toTransportationItem() 최소값 1분으로 수정
1 parent c2f5d7f commit 1e71e68

6 files changed

Lines changed: 39 additions & 23 deletions

File tree

data/travel/src/main/java/com/yapp/ndgl/data/travel/model/AddItineraryRequest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ data class AddItineraryRequest(
99
val day: Int,
1010
val sequence: Int,
1111
val startTime: String? = null,
12-
val estimatedDuration: String? = null,
12+
val estimatedDuration: Int,
1313
val memo: String? = null,
1414
@SerialName("budget")
1515
val cost: Int? = null,

data/travel/src/main/java/com/yapp/ndgl/data/travel/repository/PlaceRepository.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class PlaceRepository @Inject constructor(
3434
val requestBuilder = FindAutocompletePredictionsRequest.builder()
3535
.setQuery(keyword)
3636
.setSessionToken(sessionToken)
37-
// .setCountries(countryCode)
3837
.setLocationBias(bias)
3938

4039
val response = placesClient.findAutocompletePredictions(requestBuilder.build()).await()

data/travel/src/main/java/com/yapp/ndgl/data/travel/repository/UserTravelRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class UserTravelRepository @Inject constructor(
138138
day: Int,
139139
sequence: Int,
140140
startTime: String? = null,
141-
estimatedDuration: String? = null,
141+
estimatedDuration: Int,
142142
cost: Int? = null,
143143
memo: String? = null,
144144
distanceKm: Double? = null,

feature/travel/src/main/java/com/yapp/ndgl/feature/travel/model/PlaceInfo.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package com.yapp.ndgl.feature.travel.model
22

33
import com.yapp.ndgl.core.util.formatDecimal
44
import com.yapp.ndgl.data.travel.model.PlaceDetailResponse
5-
import java.time.DayOfWeek
6-
import java.time.LocalDate
7-
import java.time.format.DateTimeFormatter
5+
import kotlinx.datetime.DateTimeUnit
6+
import kotlinx.datetime.DayOfWeek
7+
import kotlinx.datetime.LocalDate
8+
import kotlinx.datetime.plus
89
import kotlin.time.Duration
910
import kotlin.time.Duration.Companion.hours
1011

@@ -62,12 +63,13 @@ fun PlaceDetailResponse.toPlaceInfo(): PlaceInfo {
6263
websiteUrl = place.websiteUri,
6364
)
6465
}
66+
6567
fun List<String>?.toOpeningHours(startDate: String, day: Int): String? {
66-
if (this.isNullOrEmpty() || startDate.isBlank()) return null
68+
if (this.isNullOrEmpty() || startDate.isBlank() || day <= 0) return null
6769

6870
val targetDayOfWeek = runCatching {
69-
val travelStartDate = LocalDate.parse(startDate, DateTimeFormatter.ISO_LOCAL_DATE)
70-
val targetDate = travelStartDate.plusDays((day - 1).toLong())
71+
val travelStartDate = LocalDate.parse(startDate)
72+
val targetDate = travelStartDate.plus(day - 1, DateTimeUnit.DAY)
7173
targetDate.dayOfWeek
7274
}.getOrNull() ?: return null
7375

feature/travel/src/main/java/com/yapp/ndgl/feature/travel/model/TransportSegment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data class TransportSegment(
3232
fun toTransportationItem(): TransportationItem {
3333
return TransportationItem(
3434
mode = type.toTransportCategory(),
35-
timeMin = duration.inWholeMinutes.toInt(),
35+
timeMin = duration.inWholeMinutes.toInt().coerceAtLeast(1),
3636
)
3737
}
3838
}

feature/travel/src/main/java/com/yapp/ndgl/feature/travel/traveldetail/TravelDetailViewModel.kt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,23 @@ class TravelDetailViewModel @AssistedInject constructor(
117117
val dayIndex = event.day - 1
118118
val currentItinerary = state.value.itineraries.getOrNull(dayIndex) ?: return
119119
val newSequence = currentItinerary.places.size + 1
120-
val lastPlace = currentItinerary.places.last()
120+
val lastPlace = currentItinerary.places.lastOrNull()
121121

122122
// 추가된 장소로 가는 교통수단 계산
123-
val newTransportSegment = computeRoute(
124-
originLatitude = lastPlace.placeInfo.latitude,
125-
originLongitude = lastPlace.placeInfo.longitude,
126-
destinationLatitude = event.latitude,
127-
destinationLongitude = event.longitude,
128-
newGooglePlaceId = event.googlePlaceId,
129-
travelMode = TravelMode.TRANSIT,
130-
)
131-
val (distanceKm, transportation) = if (currentItinerary.places.isNotEmpty()) {
123+
val newTransportSegment = if (lastPlace != null) {
124+
computeRoute(
125+
originLatitude = lastPlace.placeInfo.latitude,
126+
originLongitude = lastPlace.placeInfo.longitude,
127+
destinationLatitude = event.latitude,
128+
destinationLongitude = event.longitude,
129+
newGooglePlaceId = event.googlePlaceId,
130+
travelMode = TravelMode.TRANSIT,
131+
)
132+
} else {
133+
null
134+
}
135+
136+
val (distanceKm, transportation) = if (!currentItinerary.places.isNullOrEmpty()) {
132137
newTransportSegment?.distanceKm to listOfNotNull(newTransportSegment?.toTransportationItem())
133138
} else {
134139
null to null
@@ -140,8 +145,17 @@ class TravelDetailViewModel @AssistedInject constructor(
140145
googlePlaceId = event.googlePlaceId,
141146
day = event.day,
142147
sequence = newSequence,
143-
startTime = null,
144-
estimatedDuration = "${event.estimatedDuration}",
148+
startTime = if (lastPlace == null) {
149+
null
150+
} else {
151+
(
152+
lastPlace.startTime + lastPlace.placeInfo.estimatedDuration + (
153+
newTransportSegment?.duration
154+
?: 0.hours
155+
)
156+
).parseDurationToTimeString()
157+
},
158+
estimatedDuration = event.estimatedDuration,
145159
cost = null,
146160
memo = null,
147161
distanceKm = distanceKm,
@@ -166,7 +180,8 @@ class TravelDetailViewModel @AssistedInject constructor(
166180
userData = TravelPlace.UserData(
167181
estimatedDuration = response.estimatedDuration.minutes,
168182
),
169-
startTime = lastPlace.startTime + lastPlace.placeInfo.estimatedDuration + (newTransportSegment?.duration ?: 0.hours),
183+
startTime = (lastPlace?.startTime ?: Itinerary.DEFAULT_START_TIME.hours) +
184+
(lastPlace?.placeInfo?.estimatedDuration ?: 1.hours) + (newTransportSegment?.duration ?: 0.hours),
170185
transportToNext = null,
171186
)
172187

0 commit comments

Comments
 (0)