Пример #1
0
        public async Task <IActionResult> GetAsync([FromRoute] string locationId, [FromQuery] string lang)
        {
            //Should build another layer of services - didnt have time for it, so i write some logic in controller
            var result = new WeatherResultsDTO();
            var fav    = await _favoritesRepo.GetFavoriteAsync(locationId);

            if (fav == null)
            {
                var externalResult = await _accWheatherServices.GetWeatherResults(lang, locationId);

                result = new WeatherResultsDTO
                {
                    Temperature = externalResult.Temperature.Metric.Value,
                    WeatherText = externalResult.WeatherText
                };
            }
            else
            {
                result = new WeatherResultsDTO
                {
                    Temperature = fav.TempInCelsius,
                    WeatherText = fav.WeatherText
                };
            }

            return(Ok(result));
        }
Пример #2
0
        public async Task <IActionResult> AddLocationAsync([FromBody] FavoriteInputDTO input, [FromQuery] string lang)
        {
            //validation if exists and error handling missing, didnt have time
            var externalResult = await _accWheatherServices.GetWeatherResults(lang, input.LocationId);

            var fav = new Favorite
            {
                WeatherText   = externalResult.WeatherText,
                LocationId    = input.LocationId,
                TempInCelsius = externalResult.Temperature.Metric.Value,
                LocalizedName = input.LocalizedName
            };
            await _favoritesRepo.AddFavoriteAsync(fav);

            return(Ok());
        }