From ad9f31681c923388a166c51e7fb2fa7610d56d9f Mon Sep 17 00:00:00 2001 From: Mahmoud Akram Al-Mallahi Date: Sat, 15 Jul 2023 00:29:05 +0300 Subject: [PATCH 1/4] fix entity and Dto --- .../kotlin/data/remote/dto/Condition.kt | 12 ++ src/jvmMain/kotlin/data/remote/dto/Current.kt | 52 +++++++++ .../kotlin/data/remote/dto/Location.kt | 22 ++++ .../kotlin/data/remote/dto/WeatherDTO.kt | 107 ++---------------- .../kotlin/data/remote/dto/WeatherDto.kt | 31 ----- .../kotlin/domain/entity/ConditionEntity.kt | 7 ++ .../domain/entity/CurrentWeatherEntity.kt | 3 +- .../kotlin/domain/entity/DaysWeatherEntity.kt | 9 +- .../kotlin/domain/entity/ForestEntities.kt | 9 +- .../kotlin/domain/entity/WeatherEntity.kt | 6 - 10 files changed, 109 insertions(+), 149 deletions(-) create mode 100644 src/jvmMain/kotlin/data/remote/dto/Condition.kt create mode 100644 src/jvmMain/kotlin/data/remote/dto/Current.kt create mode 100644 src/jvmMain/kotlin/data/remote/dto/Location.kt delete mode 100644 src/jvmMain/kotlin/data/remote/dto/WeatherDto.kt create mode 100644 src/jvmMain/kotlin/domain/entity/ConditionEntity.kt diff --git a/src/jvmMain/kotlin/data/remote/dto/Condition.kt b/src/jvmMain/kotlin/data/remote/dto/Condition.kt new file mode 100644 index 0000000..aa330e2 --- /dev/null +++ b/src/jvmMain/kotlin/data/remote/dto/Condition.kt @@ -0,0 +1,12 @@ +package data.remote.dto + +import com.google.gson.annotations.SerializedName + +data class Condition( + @SerializedName("code") + val code: Int? = null, + @SerializedName("icon") + val icon: String? = null, + @SerializedName("text") + val text: String? = null +) \ No newline at end of file diff --git a/src/jvmMain/kotlin/data/remote/dto/Current.kt b/src/jvmMain/kotlin/data/remote/dto/Current.kt new file mode 100644 index 0000000..4bac399 --- /dev/null +++ b/src/jvmMain/kotlin/data/remote/dto/Current.kt @@ -0,0 +1,52 @@ +package data.remote.dto + +import com.google.gson.annotations.SerializedName + +data class Current( + @SerializedName("cloud") + val cloud: Int? = null, + @SerializedName("condition") + val condition: Condition? = null, + @SerializedName("feelslike_c") + val feelslikeC: Double? = null, + @SerializedName("feelslike_f") + val feelslikeF: Double? = null, + @SerializedName("gust_kph") + val gustKph: Double? = null, + @SerializedName("gust_mph") + val gustMph: Double? = null, + @SerializedName("humidity") + val humidity: Int? = null, + @SerializedName("is_day") + val isDay: Int? = null, + @SerializedName("last_updated") + val lastUpdated: String? = null, + @SerializedName("last_updated_epoch") + val lastUpdatedEpoch: Int? = null, + @SerializedName("precip_in") + val precipIn: Double? = null, + @SerializedName("precip_mm") + val precipMm: Double? = null, + @SerializedName("pressure_in") + val pressureIn: Double? = null, + @SerializedName("pressure_mb") + val pressureMb: Double? = null, + @SerializedName("temp_c") + val tempC: Double? = null, + @SerializedName("temp_f") + val tempF: Double? = null, + @SerializedName("uv") + val uv: Double? = null, + @SerializedName("vis_km") + val visKm: Double? = null, + @SerializedName("vis_miles") + val visMiles: Double? = null, + @SerializedName("wind_degree") + val windDegree: Int? = null, + @SerializedName("wind_dir") + val windDir: String? = null, + @SerializedName("wind_kph") + val windKph: Double? = null, + @SerializedName("wind_mph") + val windMph: Double? = null +) \ No newline at end of file diff --git a/src/jvmMain/kotlin/data/remote/dto/Location.kt b/src/jvmMain/kotlin/data/remote/dto/Location.kt new file mode 100644 index 0000000..7c6c38d --- /dev/null +++ b/src/jvmMain/kotlin/data/remote/dto/Location.kt @@ -0,0 +1,22 @@ +package data.remote.dto + +import com.google.gson.annotations.SerializedName + +data class Location( + @SerializedName("country") + val country: String? = null, + @SerializedName("lat") + val lat: Double? = null, + @SerializedName("localtime") + val localtime: String? = null, + @SerializedName("localtime_epoch") + val localtimeEpoch: Int? = null, + @SerializedName("lon") + val lon: Double? = null, + @SerializedName("name") + val name: String? = null, + @SerializedName("region") + val region: String? = null, + @SerializedName("tz_id") + val tzId: String? = null +) \ No newline at end of file diff --git a/src/jvmMain/kotlin/data/remote/dto/WeatherDTO.kt b/src/jvmMain/kotlin/data/remote/dto/WeatherDTO.kt index c480823..b60f312 100644 --- a/src/jvmMain/kotlin/data/remote/dto/WeatherDTO.kt +++ b/src/jvmMain/kotlin/data/remote/dto/WeatherDTO.kt @@ -1,101 +1,10 @@ package data.remote.dto - -import kotlinx.serialization.SerialName - - -data class WeatherDTO( - @SerialName("query") - val query: Query -) { - - data class Query( - @SerialName("custom_id") - val customId: String, - @SerialName("q") - val q: String, - @SerialName("location") - val location: Location, - @SerialName("current") - val current: Current - ) { - - data class Location( - @SerialName("name") - val name: String, - @SerialName("region") - val region: String, - @SerialName("country") - val country: String, - @SerialName("lat") - val lat: Double, - @SerialName("lon") - val lon: Double, - @SerialName("tz_id") - val tzId: String, - @SerialName("localtime_epoch") - val localtimeEpoch: Int, - @SerialName("localtime") - val localtime: String - ) - - data class Current( - @SerialName("last_updated_epoch") - val lastUpdatedEpoch: Int, - @SerialName("last_updated") - val lastUpdated: String, - @SerialName("temp_c") - val tempC: Double, - @SerialName("temp_f") - val tempF: Double, - @SerialName("is_day") - val isDay: Int, - @SerialName("condition") - val condition: Condition, - @SerialName("wind_mph") - val windMph: Double, - @SerialName("wind_kph") - val windKph: Double, - @SerialName("wind_degree") - val windDegree: Int, - @SerialName("wind_dir") - val windDir: String, - @SerialName("pressure_mb") - val pressureMb: Double, - @SerialName("pressure_in") - val pressureIn: Double, - @SerialName("precip_mm") - val precipMm: Double, - @SerialName("precip_in") - val precipIn: Double, - @SerialName("humidity") - val humidity: Int, - @SerialName("cloud") - val cloud: Int, - @SerialName("feelslike_c") - val feelslikeC: Double, - @SerialName("feelslike_f") - val feelslikeF: Double, - @SerialName("vis_km") - val visKm: Double, - @SerialName("vis_miles") - val visMiles: Double, - @SerialName("uv") - val uv: Double, - @SerialName("gust_mph") - val gustMph: Double, - @SerialName("gust_kph") - val gustKph: Double - ) { - - data class Condition( - @SerialName("text") - val text: String, - @SerialName("icon") - val icon: String, - @SerialName("code") - val code: Int - ) - } - } -} \ No newline at end of file +import com.google.gson.annotations.SerializedName + +data class WeatherDto( + @SerializedName("current") + val current: Current? = null, + @SerializedName("location") + val location: Location? = null +) \ No newline at end of file diff --git a/src/jvmMain/kotlin/data/remote/dto/WeatherDto.kt b/src/jvmMain/kotlin/data/remote/dto/WeatherDto.kt deleted file mode 100644 index 63fe598..0000000 --- a/src/jvmMain/kotlin/data/remote/dto/WeatherDto.kt +++ /dev/null @@ -1,31 +0,0 @@ -package data.remote.dto - -import com.google.gson.annotations.SerializedName - - - -data class WeatherDto( - val current: CurrentDto?, - val location: LocationDto? -) - - -data class ConditionDto( - val code: Int?, - val icon: String?, - val text: String? -) - - -data class LocationDto( - val country: String?, - val lat: Double?, - val localtime: String?, - @SerializedName("localtime_epoch") - val localtimeEpoch: Int?, - val lon: Double?, - val name: String?, - val region: String?, - @SerializedName("tz_id") - val tzId: String? -) \ No newline at end of file diff --git a/src/jvmMain/kotlin/domain/entity/ConditionEntity.kt b/src/jvmMain/kotlin/domain/entity/ConditionEntity.kt new file mode 100644 index 0000000..d700259 --- /dev/null +++ b/src/jvmMain/kotlin/domain/entity/ConditionEntity.kt @@ -0,0 +1,7 @@ +package domain.entity + +data class ConditionEntity( + val code: Int?, + val icon: String?, + val text: String? +) \ No newline at end of file diff --git a/src/jvmMain/kotlin/domain/entity/CurrentWeatherEntity.kt b/src/jvmMain/kotlin/domain/entity/CurrentWeatherEntity.kt index 9d76b60..7fdada0 100644 --- a/src/jvmMain/kotlin/domain/entity/CurrentWeatherEntity.kt +++ b/src/jvmMain/kotlin/domain/entity/CurrentWeatherEntity.kt @@ -1,10 +1,9 @@ package domain.entity -import data.remote.dto.ConditionDto data class CurrentWeatherEntity( val cloud: Int?, - val condition: ConditionDto?, + val condition: ConditionEntity?, val feelslikeC: Double?, val feelslikeF: Double?, val gustKph: Double?, diff --git a/src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt b/src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt index a0626cc..ef9ce00 100644 --- a/src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt +++ b/src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt @@ -1,11 +1,8 @@ package domain.entity -import data.remote.dto.CurrentDto -import data.remote.dto.ForecastDto -import data.remote.dto.LocationDto data class DaysWeatherEntity( - val current: CurrentDto?, - val forecast: ForecastDto?, - val location: LocationDto? + val current: CurrentWeatherEntity?, + val forecast: ForecastEntity?, + val location: LocationEntity? ) diff --git a/src/jvmMain/kotlin/domain/entity/ForestEntities.kt b/src/jvmMain/kotlin/domain/entity/ForestEntities.kt index 8be0e6c..401209c 100644 --- a/src/jvmMain/kotlin/domain/entity/ForestEntities.kt +++ b/src/jvmMain/kotlin/domain/entity/ForestEntities.kt @@ -1,6 +1,5 @@ package domain.entity -import data.remote.dto.ConditionDto data class ForecastEntity( val forecastDay: List? @@ -10,7 +9,7 @@ data class ForecastDayEntity( val date: String?, val dateEpoch: Int?, val day: DayEntity?, - val hour: List? + val hour: List? ) data class AstroEntity( @@ -27,7 +26,7 @@ data class DayEntity( val avgtempF: Double?, val avgvisKm: Double?, val avgvisMiles: Double?, - val condition: ConditionDto?, + val condition: ConditionEntity?, val dailyChanceOfRain: Int?, val dailyChanceOfSnow: Int?, val dailyWillItRain: Int?, @@ -43,11 +42,11 @@ data class DayEntity( val totalsnowCm: Double?, ) -data class HourDto( +data class HourEntity( val chanceOfRain: Int?, val chanceOfSnow: Int?, val cloud: Int?, - val condition: ConditionDto?, + val condition: ForecastEntity?, val dewpointC: Double?, val dewpointF: Double?, val feelslikeC: Double?, diff --git a/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt b/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt index 3ba3919..b92f151 100644 --- a/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt +++ b/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt @@ -5,9 +5,3 @@ data class WeatherEntity( val location: LocationEntity? ) -data class ConditionEntity( - val code: Int?, - val icon: String?, - val text: String? -) - From 5e3d01bfd8e9073a957b13d1ec73f9d660c0abe7 Mon Sep 17 00:00:00 2001 From: Mahmoud Akram Al-Mallahi Date: Sat, 15 Jul 2023 00:36:14 +0300 Subject: [PATCH 2/4] fix entity and Dto --- src/jvmMain/kotlin/data/remote/dto/CurrentDto.kt | 2 +- src/jvmMain/kotlin/data/remote/dto/DaysWeatherDto.kt | 2 +- src/jvmMain/kotlin/data/remote/dto/ForecastDayDto.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jvmMain/kotlin/data/remote/dto/CurrentDto.kt b/src/jvmMain/kotlin/data/remote/dto/CurrentDto.kt index 11c159c..a6f3fd8 100644 --- a/src/jvmMain/kotlin/data/remote/dto/CurrentDto.kt +++ b/src/jvmMain/kotlin/data/remote/dto/CurrentDto.kt @@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName data class CurrentDto( val cloud: Int?, - val condition: ConditionDto?, + val condition: Condition?, @SerializedName("feelslike_c") val feelslikeC: Double?, @SerializedName("feelslike_f") diff --git a/src/jvmMain/kotlin/data/remote/dto/DaysWeatherDto.kt b/src/jvmMain/kotlin/data/remote/dto/DaysWeatherDto.kt index dc4d795..4477aec 100644 --- a/src/jvmMain/kotlin/data/remote/dto/DaysWeatherDto.kt +++ b/src/jvmMain/kotlin/data/remote/dto/DaysWeatherDto.kt @@ -6,5 +6,5 @@ package data.remote.dto data class DaysWeatherDto( val current: CurrentDto?, val forecast: ForecastDto?, - val location: LocationDto? + val location: Location? ) \ No newline at end of file diff --git a/src/jvmMain/kotlin/data/remote/dto/ForecastDayDto.kt b/src/jvmMain/kotlin/data/remote/dto/ForecastDayDto.kt index c36382f..cd4c210 100644 --- a/src/jvmMain/kotlin/data/remote/dto/ForecastDayDto.kt +++ b/src/jvmMain/kotlin/data/remote/dto/ForecastDayDto.kt @@ -44,7 +44,7 @@ data class DayDto( val avgvisKm: Double?, @SerializedName("avgvis_miles") val avgvisMiles: Double?, - val condition: ConditionDto?, + val condition: Condition?, @SerializedName("daily_chance_of_rain") val dailyChanceOfRain: Int?, @SerializedName("daily_chance_of_snow") @@ -81,7 +81,7 @@ data class HourDto( @SerializedName("chance_of_snow") val chanceOfSnow: Int?, val cloud: Int?, - val condition: ConditionDto?, + val condition: Condition?, @SerializedName("dewpoint_c") val dewpointC: Double?, @SerializedName("dewpoint_f") From ac952f001f3eb7bad1274d438f1de13e61624fd7 Mon Sep 17 00:00:00 2001 From: Mahmoud Akram Al-Mallahi Date: Sun, 16 Jul 2023 00:41:52 +0300 Subject: [PATCH 3/4] fix WeatherDto and create UIState --- src/jvmMain/kotlin/app/EventUIState.kt | 5 ++ src/jvmMain/kotlin/app/WeatherUIState.kt | 35 +++++++++++++ .../dto/{WeatherDTO.kt => WeatherDto.kt} | 0 .../data/remote/mapper/WeatherMapper.kt | 52 +++++++++---------- .../usecase/GetForecastByLocationUseCase.kt | 8 +-- .../usecase/GetForecastByNameUseCase.kt | 10 ++-- .../usecase/GetWeatherByLocationUseCase.kt | 8 +-- .../domain/usecase/GetWeatherByNameUseCase.kt | 10 ++-- 8 files changed, 84 insertions(+), 44 deletions(-) create mode 100644 src/jvmMain/kotlin/app/EventUIState.kt create mode 100644 src/jvmMain/kotlin/app/WeatherUIState.kt rename src/jvmMain/kotlin/data/remote/dto/{WeatherDTO.kt => WeatherDto.kt} (100%) diff --git a/src/jvmMain/kotlin/app/EventUIState.kt b/src/jvmMain/kotlin/app/EventUIState.kt new file mode 100644 index 0000000..ca9e0ed --- /dev/null +++ b/src/jvmMain/kotlin/app/EventUIState.kt @@ -0,0 +1,5 @@ +package app + +interface EventUIState { + fun onClickSearch(text: String) +} \ No newline at end of file diff --git a/src/jvmMain/kotlin/app/WeatherUIState.kt b/src/jvmMain/kotlin/app/WeatherUIState.kt new file mode 100644 index 0000000..26feb80 --- /dev/null +++ b/src/jvmMain/kotlin/app/WeatherUIState.kt @@ -0,0 +1,35 @@ +package app + + +data class WeatherUIState( + val search: String = "", + val cloud: Int = 0, + val humidity: Int = 0, + val wind: Double = 0.0, + val chanceOfRain: Int = 0, + val weeklyForeCase: WeeklyForeCaseUIState = WeeklyForeCaseUIState(), + val temp: Double = 0.0, + val condition: ConditionUIState = ConditionUIState(), + val location: LocationUIState = LocationUIState() +) + +data class WeeklyForeCaseUIState( + val foreCaseDay: List = emptyList() +) + +data class ForeCaseDayUIState( + val date: String = "", + val maxTemp: Double = 0.0, + val minTemp: Double = 0.0, + val icon: String = "" +) + +data class ConditionUIState( + val text: String = "", + val icon: String = "" +) + +data class LocationUIState( + val name: String = "", + val localTime: String = "" +) \ No newline at end of file diff --git a/src/jvmMain/kotlin/data/remote/dto/WeatherDTO.kt b/src/jvmMain/kotlin/data/remote/dto/WeatherDto.kt similarity index 100% rename from src/jvmMain/kotlin/data/remote/dto/WeatherDTO.kt rename to src/jvmMain/kotlin/data/remote/dto/WeatherDto.kt diff --git a/src/jvmMain/kotlin/data/remote/mapper/WeatherMapper.kt b/src/jvmMain/kotlin/data/remote/mapper/WeatherMapper.kt index b1a08ba..2d434cb 100644 --- a/src/jvmMain/kotlin/data/remote/mapper/WeatherMapper.kt +++ b/src/jvmMain/kotlin/data/remote/mapper/WeatherMapper.kt @@ -1,40 +1,40 @@ package data.remote.mapper -import data.remote.dto.WeatherDTO +import data.remote.dto.WeatherDto import domain.Weather -fun List.mapToDomainModel() = +fun List.mapToDomainModel() = map { Weather( location = Weather.Location( - name = it.query.location.name, - region = it.query.location.region, - country = it.query.location.country, - lat = it.query.location.lat, - lon = it.query.location.lon, - localtime = it.query.location.localtime + name = it.location?.name ?: "", + region = it.location?.region ?: "", + country = it.location?.country ?: "", + lat = it.location?.lat ?: 0.0, + lon = it.location?.lon ?: 0.0, + localtime = it.location?.localtime ?: "" ), condition = Weather.Condition( - text = it.query.current.condition.text, - icon = it.query.current.condition.icon, - code = it.query.current.condition.code + text = it.current?.condition?.text ?: "", + icon = it.current?.condition?.icon ?: "", + code = it.current?.condition?.code ?: 0 ), current = Weather.Current( - lastUpdated = it.query.current.lastUpdated, - tempC = it.query.current.tempC, - tempF = it.query.current.tempF, - isDay = it.query.current.isDay, - windMph = it.query.current.windMph, - windKph = it.query.current.windKph, - windDegree = it.query.current.windDegree, - windDir = it.query.current.windDir, - pressureMb = it.query.current.pressureMb, - pressureIn = it.query.current.pressureIn, - humidity = it.query.current.humidity, - cloud = it.query.current.cloud, - feelslikeC = it.query.current.feelslikeC, - feelslikeF = it.query.current.feelslikeF, - uv = it.query.current.uv + lastUpdated = it.current?.lastUpdated ?: "", + tempC = it.current?.tempC ?: 0.0, + tempF = it.current?.tempF ?: 0.0, + isDay = it.current?.isDay ?: 0, + windMph = it.current?.windMph ?: 0.0, + windKph = it.current?.windKph ?: 0.0, + windDegree = it.current?.windDegree ?: 0, + windDir = it.current?.windDir ?: "", + pressureMb = it.current?.pressureMb ?: 0.0, + pressureIn = it.current?.pressureIn ?: 0.0, + humidity = it.current?.humidity ?: 0, + cloud = it.current?.cloud ?: 0, + feelslikeC = it.current?.feelslikeC ?: 0.0, + feelslikeF = it.current?.feelslikeF ?: 0.0, + uv = it.current?.uv ?: 0.0 ) ) } \ No newline at end of file diff --git a/src/jvmMain/kotlin/domain/usecase/GetForecastByLocationUseCase.kt b/src/jvmMain/kotlin/domain/usecase/GetForecastByLocationUseCase.kt index 0abac81..221ce18 100644 --- a/src/jvmMain/kotlin/domain/usecase/GetForecastByLocationUseCase.kt +++ b/src/jvmMain/kotlin/domain/usecase/GetForecastByLocationUseCase.kt @@ -1,10 +1,10 @@ package domain.usecase -import domain.repository.IWeatherRepository +import domain.repository.WeatherRepository -class GetForecastByLocationUseCase(private val iWeatherRepository: IWeatherRepository) { +class GetForecastByLocationUseCase(private val iWeatherRepository: WeatherRepository) { - suspend operator fun invoke(latitude :Double, longitude:Double){ - return iWeatherRepository.getForecastWeatherByLocation(latitude = latitude, longitude = longitude) + suspend operator fun invoke(query: String, days: Int?, getAirQuality: String?, getWeatherAlerts: String?,){ + return iWeatherRepository.getWeatherForecast(query, days,getAirQuality, getWeatherAlerts) } } \ No newline at end of file diff --git a/src/jvmMain/kotlin/domain/usecase/GetForecastByNameUseCase.kt b/src/jvmMain/kotlin/domain/usecase/GetForecastByNameUseCase.kt index 6d010e7..2bc720f 100644 --- a/src/jvmMain/kotlin/domain/usecase/GetForecastByNameUseCase.kt +++ b/src/jvmMain/kotlin/domain/usecase/GetForecastByNameUseCase.kt @@ -1,10 +1,10 @@ package domain.usecase -import domain.repository.IWeatherRepository +import domain.repository.WeatherRepository -class GetForecastByNameUseCase(private val iWeatherRepository: IWeatherRepository) { +class GetForecastByNameUseCase(private val iWeatherRepository: WeatherRepository) { - suspend operator fun invoke(cityName: String){ - return iWeatherRepository.getForecastWeatherByName(cityName = cityName) - } +// suspend operator fun invoke(cityName: String){ +// return iWeatherRepository.getWeatherForecast() +// } } \ No newline at end of file diff --git a/src/jvmMain/kotlin/domain/usecase/GetWeatherByLocationUseCase.kt b/src/jvmMain/kotlin/domain/usecase/GetWeatherByLocationUseCase.kt index a037d9a..38da4de 100644 --- a/src/jvmMain/kotlin/domain/usecase/GetWeatherByLocationUseCase.kt +++ b/src/jvmMain/kotlin/domain/usecase/GetWeatherByLocationUseCase.kt @@ -1,9 +1,9 @@ package domain.usecase -import domain.repository.IWeatherRepository +import domain.repository.WeatherRepository -class GetWeatherByLocationUseCase(private val iWeatherRepository: IWeatherRepository) { - suspend operator fun invoke(latitude :Double, longitude:Double){ - return iWeatherRepository.getCurrentWeatherByLocation(latitude = latitude, longitude = longitude) +class GetWeatherByLocationUseCase(private val iWeatherRepository: WeatherRepository) { + suspend operator fun invoke(query: String, getAirQuality: String?,){ + return iWeatherRepository.getCurrentWeather(query = query, getAirQuality = getAirQuality) } } \ No newline at end of file diff --git a/src/jvmMain/kotlin/domain/usecase/GetWeatherByNameUseCase.kt b/src/jvmMain/kotlin/domain/usecase/GetWeatherByNameUseCase.kt index 63851f3..38568a0 100644 --- a/src/jvmMain/kotlin/domain/usecase/GetWeatherByNameUseCase.kt +++ b/src/jvmMain/kotlin/domain/usecase/GetWeatherByNameUseCase.kt @@ -1,9 +1,9 @@ package domain.usecase -import domain.repository.IWeatherRepository +import domain.repository.WeatherRepository -class GetWeatherByNameUseCase(private val iWeatherRepository: IWeatherRepository) { - suspend operator fun invoke(cityName: String){ - return iWeatherRepository.getCurrentWeatherByName(cityName = cityName) - } +class GetWeatherByNameUseCase(private val iWeatherRepository: WeatherRepository) { +// suspend operator fun invoke(cityName: String){ +// return iWeatherRepository.getCurrentWeatherByName(cityName = cityName) +// } } \ No newline at end of file From 86c7b843ddfc7e2c1447de0c0dcc259bd0dd404e Mon Sep 17 00:00:00 2001 From: Mahmoud Akram Al-Mallahi Date: Sun, 16 Jul 2023 04:29:47 +0300 Subject: [PATCH 4/4] create UIStateMapper --- .../kotlin/app/WeatherUIStateMapper.kt | 44 +++++++++++++++++++ .../kotlin/domain/entity/DaysWeatherEntity.kt | 8 ---- .../kotlin/domain/entity/WeatherEntity.kt | 3 +- 3 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 src/jvmMain/kotlin/app/WeatherUIStateMapper.kt delete mode 100644 src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt diff --git a/src/jvmMain/kotlin/app/WeatherUIStateMapper.kt b/src/jvmMain/kotlin/app/WeatherUIStateMapper.kt new file mode 100644 index 0000000..7a9446b --- /dev/null +++ b/src/jvmMain/kotlin/app/WeatherUIStateMapper.kt @@ -0,0 +1,44 @@ +package app + +import domain.entity.* + +fun WeatherEntity.toWeatherUIState(): WeatherUIState{ + return WeatherUIState( + cloud = this.current?.cloud ?: 0, + humidity = this.current?.humidity ?: 0, + wind = this.current?.windKph ?: 0.0, + temp = this.current?.tempC ?:0.0, + condition = this.current?.condition?.toConditionUIStateMapper() ?: ConditionUIState(), + location = this.location?.toLocationUIStateMapper() ?: LocationUIState(), + weeklyForeCase = this.forecast?.toWeeklyForeCaseUIStateMapper() ?: WeeklyForeCaseUIState() + ) +} + +fun ConditionEntity.toConditionUIStateMapper(): ConditionUIState{ + return ConditionUIState( + text = this.text ?: "", + icon = this.icon ?: "" + ) +} + +fun LocationEntity.toLocationUIStateMapper(): LocationUIState{ + return LocationUIState( + name = this.name ?: "", + localTime = this.localtime ?: "" + ) +} + +fun ForecastEntity.toWeeklyForeCaseUIStateMapper(): WeeklyForeCaseUIState{ + return WeeklyForeCaseUIState( + foreCaseDay = this.forecastDay?.map { it.toForeCaseDayUIState() }.orEmpty() + ) +} + +fun ForecastDayEntity.toForeCaseDayUIState(): ForeCaseDayUIState{ + return ForeCaseDayUIState( + date = this.date ?: "", + maxTemp = this.day?.maxtempC ?: 0.0, + minTemp = this.day?.mintempC ?: 0.0, + icon = this.day?.condition?.icon ?: "" + ) +} \ No newline at end of file diff --git a/src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt b/src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt deleted file mode 100644 index ef9ce00..0000000 --- a/src/jvmMain/kotlin/domain/entity/DaysWeatherEntity.kt +++ /dev/null @@ -1,8 +0,0 @@ -package domain.entity - - -data class DaysWeatherEntity( - val current: CurrentWeatherEntity?, - val forecast: ForecastEntity?, - val location: LocationEntity? -) diff --git a/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt b/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt index b92f151..785f03a 100644 --- a/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt +++ b/src/jvmMain/kotlin/domain/entity/WeatherEntity.kt @@ -1,7 +1,8 @@ package domain.entity + data class WeatherEntity( val current: CurrentWeatherEntity?, + val forecast: ForecastEntity?, val location: LocationEntity? ) -