public async Task <WeatherForecastData> GetWeatherForecastByDate(int locationId, string date) { var request = new GetWeatherForecastByDateRequest { LocationId = locationId, Date = date }; var response = await _client.GetWeatherForecastByDateAsync(request); return(_mapper.Map <WeatherForecast, WeatherForecastData>(response.Forecast)); }
public override async Task <GetWeatherForecastResponse> GetWeatherForecastByDate(GetWeatherForecastByDateRequest request, ServerCallContext context) { if (await _featureManager.IsEnabledAsync(nameof(FeatureFlags.AllowGetForecastByDate))) { _logger.LogInformation("Now handling weather forecast request for location '{location}' at date '{date}'", request.LocationId, request.Date); var locationId = request.LocationId; var date = request.Date; if (locationId <= 0) { const string error = "Location id must be a positive integer"; throw new RpcException(new Status(StatusCode.InvalidArgument, error)); } if (string.IsNullOrEmpty(date)) { const string error = "date cannot be null or empty."; throw new RpcException(new Status(StatusCode.InvalidArgument, error)); } var forecast = await _repository.GetWeatherForecastByDate(locationId, date); if (forecast == null) { var error = $"The forecast at location {locationId} on date {date} could not be found."; _logger.LogError(error); throw new RpcException(new Status(StatusCode.NotFound, error)); } var result = _mapper.Map <WeatherForecastStoredData, WeatherForecast>(forecast); return(new GetWeatherForecastResponse { Forecast = result }); } throw new RpcException(new Status(StatusCode.Unimplemented, "This feature is disabled. Please contact a system administrator for more information.")); }