fix MeasureController.GetHisoryAsync

This commit is contained in:
Фролов 2021-12-22 12:31:37 +05:00
parent d40bced3a0
commit ea26010719
3 changed files with 15 additions and 5 deletions

View File

@ -9,7 +9,7 @@ namespace AsbCloudApp.Services
{
Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token);
Task<MeasureDto> GetLastAsync(int idWell, int idCategory, CancellationToken token);
Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token);
Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, int? idCategory, CancellationToken token);
Task<int> InsertAsync(int idWell, MeasureDto data, CancellationToken token);
Task<int> UpdateAsync(int idWell, MeasureDto data, CancellationToken token);
Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token);

View File

@ -47,10 +47,13 @@ namespace AsbCloudInfrastructure.Services
return dtos;
}
public async Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token)
public async Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, int? idCategory = null, CancellationToken token = default)
{
var query = db.Measures.Include(m => m.Category)
.Where(m => m.IdWell == idWell && !m.IsDeleted && m.IdCategory == idCategory);
.Where(m => m.IdWell == idWell && !m.IsDeleted);
if(idCategory is not null)
query = query.Where(m => m.IdCategory == idCategory);
var entities = await query
.OrderBy(m => m.Timestamp)

View File

@ -43,9 +43,16 @@ namespace AsbCloudWebApi.Controllers
return Ok(result);
}
/// <summary>
/// История замеров по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="idCategory">Категория скважины. Не обязательный параметр. По умолчанию null</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Route("history")]
public async Task<IActionResult> GetHisoryAsync([FromRoute] int idWell, [FromRoute] int idCategory, CancellationToken token = default)
[Route("history/{idCategory?}")]
public async Task<IActionResult> GetHisoryAsync([FromRoute] int idWell, int? idCategory = null, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();