public async Task <SensorReading[]> GetReadings(int id, AggregateTimeframe timeframe) { var databaseTimeframe = timeframe switch { AggregateTimeframe.OneMinute => "1M", AggregateTimeframe.FiveMinutes => "5M", AggregateTimeframe.FifteenMinutes => "15M", AggregateTimeframe.ThirtyMinutes => "30M", AggregateTimeframe.OneHour => "1H", AggregateTimeframe.FourHours => "4H", AggregateTimeframe.TwelveHours => "12H", AggregateTimeframe.OneDay => "1D", _ => throw new ArgumentOutOfRangeException(nameof(timeframe), timeframe, null) }; using var storedProcedure = Connection.CreateStoredProcedure(ProcedureNameReadingAggregateGet, new[] { new StoredProcedureParameter("id", id), new StoredProcedureParameter("timeframe", databaseTimeframe) }); await storedProcedure.ExecuteReaderAsync(); return((await storedProcedure.GetDataSetAsync <SensorReading>())?.ToArray()); } }
public async Task <IActionResult> GetAggregate(int id, AggregateTimeframe timeframe) { var results = await _sensorReadingRepository.GetReadings(id, timeframe); return(results == null ? (IActionResult)NotFound() : Ok(results)); }