fix Get* methods. add orderBy, specify dateTimeKind and return value:)

This commit is contained in:
Фролов 2021-09-29 17:05:27 +05:00
parent b60b84b45c
commit 90bdb264cb
2 changed files with 23 additions and 8 deletions

View File

@ -88,6 +88,9 @@ namespace AsbCloudInfrastructure.Services
if (dateBegin == default)
dateBegin = DateTime.Now.AddSeconds(-intervalSec);
if (dateBegin.Kind == DateTimeKind.Unspecified)
dateBegin = DateTime.SpecifyKind(dateBegin, DateTimeKind.Utc);
var datEnd = dateBegin.AddSeconds(intervalSec);
var dbSet = db.Set<TModel>();
@ -109,8 +112,11 @@ namespace AsbCloudInfrastructure.Services
query = query.Where(d => d.Id % m == 0);
}
var entities = await query.AsNoTracking()
.ToListAsync(token).ConfigureAwait(false);
var entities = await query
.OrderBy(d=>d.Date)
.AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);
var dtos = entities.Select(e => Convert(e));

View File

@ -79,15 +79,24 @@ namespace AsbCloudWebApi.Controllers
public virtual async Task<IActionResult> GetDataAsync(int idWell, DateTime begin = default,
int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
if (!isCompanyOwnsWell)
return Forbid();
if (begin == default)
begin = DateTime.Now.AddSeconds(-intervalSec);
var content = await telemetryDataService.GetAsync(idWell, begin,
intervalSec, approxPointsCount, token).ConfigureAwait(false);
if (content is null || !content.Any())
return NoContent();
return Ok(null);
return Ok(content);
}
/// <summary>
@ -113,10 +122,10 @@ namespace AsbCloudWebApi.Controllers
if (!isCompanyOwnsWell)
return Forbid();
DatesRangeDto dataDatesRange = await telemetryDataService.GetDataDatesRangeAsync(idWell,
var dataDatesRange = await telemetryDataService.GetDataDatesRangeAsync(idWell,
token).ConfigureAwait(false);
return Ok(null);
return Ok(dataDatesRange);
}
}