-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add weather and geo webclient for current and forecast weathe (#43)
* add weather and geo webclient for current and forecast weather, also add tests.
- Loading branch information
Showing
71 changed files
with
1,830 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
backend/src/main/kotlin/com/tul/backend/auth/dto/AuthUserBase.kt
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
backend/src/main/kotlin/com/tul/backend/auth/dto/AuthUserDTO.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ion/jackson/TrimmingStringDeserializer.kt → ...red/jackson/TrimmingStringDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
backend/src/main/kotlin/com/tul/backend/weather/dto/ActualWeatherDTO.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
backend/src/main/kotlin/com/tul/backend/weather/dto/CurrentWeatherDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.tul.backend.weather.dto | ||
|
||
import com.tul.backend.weather.valueobject.CurrentWeatherJson | ||
import java.time.LocalDateTime | ||
|
||
data class CurrentWeatherDTO( | ||
val time: LocalDateTime, | ||
val temperature: Double, | ||
val cloudCover: Int, | ||
val windSpeed: Double, | ||
val isDay: Boolean | ||
) { | ||
|
||
companion object { | ||
fun from(currentWeatherJson: CurrentWeatherJson): CurrentWeatherDTO { | ||
return CurrentWeatherDTO( | ||
currentWeatherJson.current.time, | ||
currentWeatherJson.current.temperature, | ||
currentWeatherJson.current.cloudCover, | ||
currentWeatherJson.current.windSpeed, | ||
currentWeatherJson.current.isDay == 1 | ||
) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
backend/src/main/kotlin/com/tul/backend/weather/dto/ForecastWeatherDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tul.backend.weather.dto | ||
|
||
import com.tul.backend.weather.valueobject.ForecastWeatherJson | ||
import java.time.LocalDate | ||
|
||
data class ForecastWeatherDTO( | ||
val time: List<LocalDate>, | ||
val maxTemperature: List<Double>, | ||
val minTemperature: List<Double>, | ||
val maxWindSpeed: List<Double> | ||
) { | ||
|
||
companion object { | ||
fun from(forecastWeatherJson: ForecastWeatherJson): ForecastWeatherDTO { | ||
return ForecastWeatherDTO( | ||
forecastWeatherJson.daily.time, | ||
forecastWeatherJson.daily.maxTemperature, | ||
forecastWeatherJson.daily.minTemperature, | ||
forecastWeatherJson.daily.maxWindSpeed | ||
) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/kotlin/com/tul/backend/weather/dto/LocationDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.tul.backend.weather.dto | ||
|
||
import com.tul.backend.weather.valueobject.LocationOutcomeJson | ||
|
||
data class LocationDTO( | ||
var latitude: Double, | ||
var longitude: Double | ||
) { | ||
|
||
companion object { | ||
fun from(locationOutcomeJson: LocationOutcomeJson): LocationDTO { | ||
return LocationDTO( | ||
latitude = locationOutcomeJson.latitude, | ||
longitude = locationOutcomeJson.longitude | ||
) | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
backend/src/main/kotlin/com/tul/backend/weather/service/WeatherHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.tul.backend.weather.service | ||
|
||
import com.tul.backend.weather.dto.CurrentWeatherDTO | ||
import com.tul.backend.weather.dto.ForecastWeatherDTO | ||
import com.tul.backend.weather.service.extractor.WeatherExtractor | ||
import com.tul.backend.weather.service.parser.WebClientParser | ||
import com.tul.backend.weather.valueobject.WeatherStatus.CURRENT | ||
import com.tul.backend.weather.valueobject.WeatherStatus.FORECAST | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Service | ||
|
||
private val log = KotlinLogging.logger {} | ||
|
||
@Service | ||
class WeatherHandler( | ||
weatherExtractors: List<WeatherExtractor>, | ||
private val webClientParser: WebClientParser | ||
) { | ||
|
||
private val weatherExtractorList = weatherExtractors.associateBy { it.weatherStatus } | ||
|
||
fun getCurrentWeather(location: String): CurrentWeatherDTO? { | ||
val weatherExtractor = weatherExtractorList[CURRENT] | ||
if (weatherExtractor == null) { | ||
log.warn { "No weather extractor found for $CURRENT" } | ||
return null | ||
} | ||
val weatherJson = weatherExtractor.getWeatherJson(location) ?: return null | ||
return webClientParser.parseCurrentWeatherJson(weatherJson) | ||
} | ||
|
||
fun getForecastWeather(location: String): ForecastWeatherDTO? { | ||
val weatherExtractor = weatherExtractorList[FORECAST] | ||
if (weatherExtractor == null) { | ||
log.warn { "No weather extractor found for $FORECAST" } | ||
return null | ||
} | ||
val weatherJson = weatherExtractor.getWeatherJson(location) ?: return null | ||
return webClientParser.parseForecastWeatherJson(weatherJson) | ||
} | ||
} |
Oops, something went wrong.