public void GetCurrentWeatherTest() { string city = "Brest"; GetCurrentWeatherResponse response = weatherService.GetCurrentWeather(city); response.Name.Should().Be(city); }
public GetCurrentWeatherResponse GetCurrentWeather(string q) { IRestResponse restResponse = _weatherClient.GetCurrentWeather(q); GetCurrentWeatherResponse response = JsonConvert.DeserializeObject <GetCurrentWeatherResponse>(restResponse.Content); return(response); }
public async Task <GetCurrentWeatherResponse> GetCurrentWeatherAsync([FromQuery] GetCurrentWeatherRequest request) { var response = new GetCurrentWeatherResponse(); try { response = await _weatherWorkflow.GetCurrentWeatherAsync(request, response).ConfigureAwait(false); if (response.IsSuccess) { response.Success("GetCurrentWeatherAsync"); } else { response.Failed("WeatherController:GetCurrentWeatherAsync"); } } catch (Exception ex) { response.Failed(ex); } return(response); }
public async Task <GetCurrentWeatherResponse> GetCurrentWeatherAsync(GetCurrentWeatherRequest request, GetCurrentWeatherResponse response) { try { response = await _weatherDataLayer.GetCurrentWeatherAsync(request, response).ConfigureAwait(false); if (!response.IsSuccess) { response.Failed("WeatherWorkflow:GetCurrentWeatherAsync"); } } catch (Exception ex) { response.Failed(ex); } return(response); }
public async Task <GetCurrentWeatherResponse> GetCurrentWeatherAsync(GetCurrentWeatherRequest request, GetCurrentWeatherResponse response) { try { // Map request var serviceRequest = _mapper.Map <Repository.Entities.Requests.GetCurrentWeatherRequest>(request); // Map response var serviceResponse = _mapper.Map <Repository.Entities.Responses.GetCurrentWeatherResponse>(response); // Call action serviceResponse = await _weatherWorkflow.GetCurrentWeatherAsync(serviceRequest, serviceResponse); // Merge response logs response.Marge(serviceResponse); // Handle response if (response.IsSuccess) { response.Temperature = serviceResponse.Temperature; response.WeatherDescription = serviceResponse.WeatherDescription; } else { response.Failed("WeatherConnector:GetCurrentWeatherAsync"); } } catch (Exception ex) { response.Failed(ex); } return(response); }
public async Task <GetCurrentWeatherResponse> GetCurrentWeatherAsync(GetCurrentWeatherRequest request, GetCurrentWeatherResponse response) { try { var placeTemperature = await _weatherRepository.GetPlaceTemperatureAsync(request.CityKey).ConfigureAwait(false); if (placeTemperature == null) { var currentConditions = await _weatherRepository.GetCurrentConditionsAsync(request.CityKey).ConfigureAwait(false); if (currentConditions != null) { var conditions = currentConditions.FirstOrDefault(); if (conditions != null) { #region Save new weather data var savedData = await _weatherRepository.InsertPlaceWeatherAndData(request.CityKey, conditions.WeatherText, conditions.Temperature.Metric.Value, request.CityName).ConfigureAwait(false); if (savedData != null) { response.Temperature = savedData.Temperature; response.WeatherDescription = savedData.WeatherText; response.Success("GetCurrentWeatherAsync"); } #endregion // Build Response } else { response.Failed("[WeatherDataLayer:GetCurrentWeatherAsync] No items found in currentConditions API result."); } } else { response.Failed("[WeatherDataLayer:GetCurrentWeatherAsync] GetCurrentConditionsAsync failed or no data found."); } } else { response.Temperature = placeTemperature.Temperature; response.WeatherDescription = placeTemperature.WeatherText; response.Success("GetCurrentWeatherAsync"); } } catch (Exception ex) { response.Failed(ex); } return(response); }