[AB-97] adding wind speed to weather command

fixing command failing non gracefully in case the location for weather was not found
This commit is contained in:
Sheldan
2023-09-05 01:44:01 +02:00
parent b369b56823
commit 156725afa6
4 changed files with 8 additions and 0 deletions

View File

@@ -102,6 +102,7 @@ public class OpenWeatherMap extends AbstractConditionableCommand {
.rain3H(weatherResult.getRainInfo() != null ? weatherResult.getRainInfo().getRain3H() : null)
.snow1H(weatherResult.getSnowInfo() != null ? weatherResult.getSnowInfo().getSnow1H() : null)
.snow3H(weatherResult.getSnowInfo() != null ? weatherResult.getSnowInfo().getSnow3H() : null)
.windSpeed(weatherResult.getWind() != null ? weatherResult.getWind().getSpeed() : null)
.visibility(weatherResult.getVisibility())
.locationName(chosenLocation.getName())
.countryKey(chosenLocation.getCountryKey())

View File

@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.webservices.openeweathermap.service;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import dev.sheldan.abstracto.webservices.openweathermap.exception.LocationNotFoundException;
import dev.sheldan.abstracto.webservices.openweathermap.model.GeoCodingLocation;
import dev.sheldan.abstracto.webservices.openweathermap.model.GeoCodingResult;
import dev.sheldan.abstracto.webservices.openweathermap.model.WeatherResult;
@@ -44,6 +45,9 @@ public class OpenWeatherMapServiceBean implements OpenWeatherMapService {
.get()
.build();
Response response = okHttpClient.newCall(request).execute();
if(response.code() == 400) {
throw new LocationNotFoundException();
}
List<GeoCodingLocation> result = gson.fromJson(response.body().string(), geoCodingType);
return GeoCodingResult
.builder()

View File

@@ -34,4 +34,5 @@ public class WeatherResponseModel {
private String countryKey;
private Color embedColor;
private Long locationId;
private Float windSpeed;
}

View File

@@ -21,6 +21,8 @@ public class WeatherResult {
private WeatherResultRain rainInfo;
@SerializedName("snow")
private WeatherResultSnow snowInfo;
@SerializedName("wind")
private WeatherResultWind wind;
@SerializedName("dt")
private Long dayTime;
@SerializedName("clouds")