Skip to content

Commit

Permalink
refactor : RunningHistoryDetailResponse 중복 코드 함수 분리 #PAR-383
Browse files Browse the repository at this point in the history
  • Loading branch information
nohjunh committed Oct 14, 2023
1 parent 4a7e218 commit 5219261
Showing 1 changed file with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,46 @@ data class RunningHistoryDetailResponse(
val distance: Double?
)

fun RunningHistoryDetailResponse.toDomainModel(): RunningHistoryDetail {
val parsedDate = startTime?.let {
fun RunningHistoryDetailResponse.getFormattedRunningTime(): String {
return this.runningTime?.toElapsedTimeString() ?: "00:00:00"
}

fun RunningHistoryDetailResponse.getParsedDate(): LocalDateTime? {
return startTime?.let {
LocalDateTime.parse(
it,
DateTimeUtils.localDateTimeFormatter
)
}
}

fun RunningHistoryDetailResponse.getFormattedDate(): String {
return getParsedDate()?.let { formatDate(it) } ?: ""
}

fun RunningHistoryDetailResponse.toDomainModel(): RunningHistoryDetail {
return RunningHistoryDetail(
id = this.id ?: "",
date = parsedDate?.let { formatDate(it) } ?: "",
runningTime = this.runningTime?.toElapsedTimeString() ?: "00:00:00",
date = getFormattedDate(),
runningTime = getFormattedRunningTime(),
distanceFormatted = formatDistanceWithComma(this.distance?.toInt() ?: 0)
)
}

fun RunningHistoryDetailResponse.toSingleRunningHistoryEntity(): SingleRunningHistoryEntity {
val parsedDate = startTime?.let {
LocalDateTime.parse(
it,
DateTimeUtils.localDateTimeFormatter
)
}

return SingleRunningHistoryEntity(
id = this.id ?: "",
date = parsedDate?.let { formatDate(it) } ?: "",
runningTime = this.runningTime?.toElapsedTimeString() ?: "00:00:00",
date = getFormattedDate(),
runningTime = getFormattedRunningTime(),
distanceFormatted = formatDistanceWithComma(this.distance?.toInt() ?: 0)
)
}

fun RunningHistoryDetailResponse.toBattleRunningHistoryEntity(): BattleRunningHistoryEntity {
val parsedDate = startTime?.let {
LocalDateTime.parse(
it,
DateTimeUtils.localDateTimeFormatter
)
}

return BattleRunningHistoryEntity(
id = this.id ?: "",
date = parsedDate?.let { formatDate(it) } ?: "",
runningTime = this.runningTime?.toElapsedTimeString() ?: "00:00:00",
date = getFormattedDate(),
runningTime = getFormattedRunningTime(),
distanceFormatted = formatDistanceWithComma(this.distance?.toInt() ?: 0)
)
}

0 comments on commit 5219261

Please sign in to comment.