public Task <List <PrecipitationVm> > Handle(GetPrecipitationQuery request, CancellationToken cancellationToken) { var currentDate = _dateTimeProvider.GetUtcNow(); request.WithDefaultValues(currentDate.AddDays(-2), currentDate); int granulation = (int)(request.Granulation ?? default); Debug.Assert(request.From != null, "request.From != null"); var fromDate = request.From.Value; return(_applicationDbContext.WeatherStationPrecipitation .AsNoTracking() .Where(x => x.MeasurementStartTime >= request.From && x.MeasurementEndTime <= request.To) .Select(x => new { TimestampGroup = granulation == (int)DateRangeGranulation.Year ? EF.Functions.DateDiffYear(fromDate, x.MeasurementEndTime) : granulation == (int)DateRangeGranulation.Month ? EF.Functions.DateDiffMonth(fromDate, x.MeasurementEndTime) : EF.Functions.DateDiffSecond(fromDate, x.MeasurementEndTime) / granulation, x.Rain, }) .GroupBy(x => x.TimestampGroup) .OrderBy(x => x.Key) .Select(g => new PrecipitationVm { Timestamp = DateTime.SpecifyKind( granulation == (int)DateRangeGranulation.Year ? fromDate.AddYears(g.Key) : granulation == (int)DateRangeGranulation.Month ? fromDate.AddMonths(g.Key) : fromDate.AddSeconds(g.Key * granulation), DateTimeKind.Utc), RainSum = Math.Round(g.Sum(x => x.Rain), 3) }) .ToListAsync(cancellationToken)); }
public Task <IEnumerable <PrecipitationVm> > GetPrecipitation(GetPrecipitationQuery query) { return(_apiClient.Get <GetPrecipitationQuery, IEnumerable <PrecipitationVm> >("WeatherData/precipitation", query)); }
public async Task <IActionResult> GetPrecipitation([FromQuery] GetPrecipitationQuery query) { return(Ok(await _mediator.Send(query))); }