|
@@ -1,12 +1,12 @@
|
|
|
-package com.example.weather.feature.weather.data.mappers
|
|
|
+package com.trifork.feature.weather.data.mappers
|
|
|
|
|
|
-import com.example.weather.feature.weather.data.remote.SunDataDto
|
|
|
-import com.example.weather.feature.weather.data.remote.WeatherDataDto
|
|
|
-import com.example.weather.feature.weather.data.remote.WeatherDto
|
|
|
-import com.example.weather.feature.weather.domain.model.SunData
|
|
|
-import com.example.weather.feature.weather.domain.model.WeatherData
|
|
|
-import com.example.weather.feature.weather.domain.model.WeatherInfo
|
|
|
-import com.example.weather.feature.weather.domain.model.WeatherType
|
|
|
+import com.trifork.feature.weather.data.remote.SunDataDto
|
|
|
+import com.trifork.feature.weather.data.remote.WeatherDataDto
|
|
|
+import com.trifork.feature.weather.data.remote.WeatherDto
|
|
|
+import com.trifork.feature.weather.domain.model.SunData
|
|
|
+import com.trifork.feature.weather.domain.model.WeatherData
|
|
|
+import com.trifork.feature.weather.domain.model.WeatherInfo
|
|
|
+import com.trifork.feature.weather.domain.model.WeatherType
|
|
|
import kotlinx.collections.immutable.ImmutableList
|
|
|
import kotlinx.collections.immutable.ImmutableMap
|
|
|
import kotlinx.collections.immutable.toImmutableList
|
|
@@ -16,10 +16,10 @@ import java.time.format.DateTimeFormatter
|
|
|
|
|
|
private data class IndexWeatherData(
|
|
|
val index: Int,
|
|
|
- val data: WeatherData
|
|
|
+ val data: com.trifork.feature.weather.domain.model.WeatherData
|
|
|
)
|
|
|
|
|
|
-fun WeatherDataDto.toWeatherDataMap(sunData: SunData): ImmutableMap<Int, ImmutableList<WeatherData>> {
|
|
|
+fun WeatherDataDto.toWeatherDataMap(sunData: com.trifork.feature.weather.domain.model.SunData): ImmutableMap<Int, ImmutableList<com.trifork.feature.weather.domain.model.WeatherData>> {
|
|
|
return time.mapIndexed { index, time ->
|
|
|
val localDateTime = LocalDateTime.parse(time, DateTimeFormatter.ISO_DATE_TIME)
|
|
|
val weatherCode = weatherCodes[index]
|
|
@@ -31,13 +31,17 @@ fun WeatherDataDto.toWeatherDataMap(sunData: SunData): ImmutableMap<Int, Immutab
|
|
|
|
|
|
IndexWeatherData(
|
|
|
index = index,
|
|
|
- data = WeatherData(
|
|
|
+ data = com.trifork.feature.weather.domain.model.WeatherData(
|
|
|
time = localDateTime,
|
|
|
temperatureCelsius = temperature,
|
|
|
pressure = pressures[index],
|
|
|
windSpeed = windSpeeds[index],
|
|
|
humidity = humidities[index],
|
|
|
- weatherType = WeatherType.fromWMO(weatherCode, isDay, isFreezing),
|
|
|
+ weatherType = com.trifork.feature.weather.domain.model.WeatherType.fromWMO(
|
|
|
+ weatherCode,
|
|
|
+ isDay,
|
|
|
+ isFreezing
|
|
|
+ ),
|
|
|
sunrise = sunrise,
|
|
|
sunset = sunset
|
|
|
)
|
|
@@ -57,21 +61,21 @@ private fun isFreezing(temperature: Double): Boolean {
|
|
|
return temperature < 0
|
|
|
}
|
|
|
|
|
|
-private fun SunDataDto.sunData(): SunData {
|
|
|
- return SunData(
|
|
|
+private fun SunDataDto.sunData(): com.trifork.feature.weather.domain.model.SunData {
|
|
|
+ return com.trifork.feature.weather.domain.model.SunData(
|
|
|
sunrise = sunrise.map { LocalDateTime.parse(it, DateTimeFormatter.ISO_DATE_TIME) },
|
|
|
sunset = sunset.map { LocalDateTime.parse(it, DateTimeFormatter.ISO_DATE_TIME) },
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-fun WeatherDto.toWeatherInfo(): WeatherInfo {
|
|
|
+fun WeatherDto.toWeatherInfo(): com.trifork.feature.weather.domain.model.WeatherInfo {
|
|
|
val weatherDataMap = weatherData.toWeatherDataMap(sunData.sunData())
|
|
|
val now = LocalDateTime.now()
|
|
|
val currentWeatherData = weatherDataMap[0]?.find {
|
|
|
val hour = if (now.minute < 30) now.hour else now.hour + 1
|
|
|
it.time.hour == hour
|
|
|
}
|
|
|
- return WeatherInfo(
|
|
|
+ return com.trifork.feature.weather.domain.model.WeatherInfo(
|
|
|
geoLocation = "",
|
|
|
weatherDataPerDay = weatherDataMap,
|
|
|
currentWeatherData = currentWeatherData
|