This commit is contained in:
@@ -58,22 +58,23 @@ namespace AyaNova.Api.Controllers
|
||||
/// <param name="maxRecords">Optional maximum records to return. If there are more records for the time period selected than this value the result will be downsampled. There is a 400 record maximum fixed default</param>
|
||||
/// <returns>Snapshot of metrics</returns>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetMetrics([FromQuery] DateTime tsStart, [FromQuery] DateTime tsEnd, [FromQuery] int? maxRecords)
|
||||
public async Task<IActionResult> GetMetrics([FromQuery, Required] DateTime? tsStart, [FromQuery, Required] DateTime? tsEnd, [FromQuery] int? maxRecords)
|
||||
{
|
||||
//Note: the date and times are nullable and required so that the regular modelstate code kicks in to ensure they are present
|
||||
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Metrics))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
//use specified values or just return all
|
||||
maxRecords ??= MAX_RECORDS_BEFORE_DOWNSAMPLING;
|
||||
|
||||
List<MetricMM> MinuteMetrics = new List<MetricMM>();
|
||||
//touniversal is because the parameters are converted to local time here, but then sent to the query as local time as well and not universal time which is what it should be
|
||||
MinuteMetrics = await ct.MetricMM.AsNoTracking().Where(z => z.t >= tsStart.ToUniversalTime() && z.t <= tsEnd.ToUniversalTime()).OrderBy(z => z.t).ToListAsync();
|
||||
MinuteMetrics = await ct.MetricMM.AsNoTracking().Where(z => z.t >= ((DateTime)tsStart).ToUniversalTime() && z.t <= ((DateTime)tsEnd).ToUniversalTime()).OrderBy(z => z.t).ToListAsync();
|
||||
|
||||
//Log
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
|
||||
|
||||
Reference in New Issue
Block a user