first commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package pl.firmatpp.kierowca.domain
|
||||
|
||||
object PhoneNumberFormatter {
|
||||
fun normalize(input: String): String {
|
||||
var digits = input.filter(Char::isDigit)
|
||||
if (digits.startsWith("00")) digits = digits.drop(2)
|
||||
if (digits.length == 9) digits = "48$digits"
|
||||
return digits
|
||||
}
|
||||
|
||||
fun mask(normalized: String): String = "+48 *** *** ${normalized.takeLast(3)}"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package pl.firmatpp.kierowca.domain
|
||||
|
||||
import kotlin.math.roundToInt
|
||||
import pl.firmatpp.kierowca.data.model.DriverRouteDto
|
||||
|
||||
data class RouteCardDisplay(
|
||||
val id: String,
|
||||
val origin: String,
|
||||
val destination: String,
|
||||
val contractLabel: String,
|
||||
val time: String,
|
||||
val status: String,
|
||||
val distanceLabel: String,
|
||||
)
|
||||
|
||||
object RouteDisplayMapper {
|
||||
fun toCard(route: DriverRouteDto): RouteCardDisplay {
|
||||
val contract = route.contractCode
|
||||
?.takeIf { it.isNotBlank() }
|
||||
?: route.contractName?.takeIf { it.isNotBlank() }
|
||||
?: route.contractorName
|
||||
|
||||
val distance = route.distanceKm
|
||||
?.takeIf { it > 0.0 }
|
||||
?.roundToInt()
|
||||
?.let { "$it km" }
|
||||
?: ""
|
||||
|
||||
return RouteCardDisplay(
|
||||
id = route.id,
|
||||
origin = route.originName.ifBlank { "Start" },
|
||||
destination = route.destinationName.ifBlank { "Cel" },
|
||||
contractLabel = contract,
|
||||
time = route.startsAt.ifBlank { "--:--" },
|
||||
status = route.status,
|
||||
distanceLabel = distance,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user