Убран суффикс "Async"

This commit is contained in:
Olga Nemt 2024-11-21 17:02:36 +05:00
parent 098c180b12
commit c751f74b35
16 changed files with 85 additions and 97 deletions

View File

@ -19,24 +19,30 @@ public class TimeSeriesController<TDto> : ControllerBase, ITimeSeriesDataApi<TDt
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
public async Task<IActionResult> Get(DateTimeOffset dateBegin, CancellationToken token)
{
var result = await this.timeSeriesDataRepository.GetAsync(dateBegin, dateEnd, token);
var result = await this.timeSeriesDataRepository.GetGtDate(dateBegin, token);
return Ok(result);
}
[HttpGet("datesRange")]
public async Task<IActionResult> GetDatesRangeAsync(CancellationToken token)
public async Task<IActionResult> GetDatesRange(CancellationToken token)
{
var result = await this.timeSeriesDataRepository.GetDatesRangeAsync(token);
var result = await this.timeSeriesDataRepository.GetDatesRange(token);
return Ok(result);
}
public Task<IActionResult> GetResampledData(DateTimeOffset dateBegin, DateTimeOffset dateEnd, int approxPointsCount = 1024)
{
throw new NotImplementedException();
}
[HttpPost]
public async Task<IActionResult> InsertRangeAsync(IEnumerable<TDto> dtos, CancellationToken token)
public async Task<IActionResult> InsertRange(IEnumerable<TDto> dtos, CancellationToken token)
{
var result = await this.timeSeriesDataRepository.InsertRange(dtos, token);
return Ok(result);
}
}

View File

@ -1,10 +1,13 @@
using Persistence.Models;
namespace Persistence.API;
public class Program
{
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
Startup.BeforeRunHandler(host);
host.Run();

View File

@ -10,8 +10,8 @@ public class TimeSeriesDataCachedRepository<TEntity, TDto> : TimeSeriesDataRepos
where TEntity : class, ITimestampedData, new()
where TDto : class, ITimeSeriesAbstractDto, new()
{
public static TDto FirstByDate { get; set; } = default!;
public static CyclicArray<TDto> LastData { get; set; } = null!;
public static TDto? FirstByDate { get; private set; }
public static CyclicArray<TDto> LastData { get; } = new CyclicArray<TDto>(CacheItemsCount);
private const int CacheItemsCount = 3600;
@ -19,8 +19,6 @@ public class TimeSeriesDataCachedRepository<TEntity, TDto> : TimeSeriesDataRepos
{
Task.Run(async () =>
{
LastData = new CyclicArray<TDto>(CacheItemsCount);
var firstDateItem = await base.GetFirstAsync(CancellationToken.None);
if (firstDateItem == null)
{
@ -35,17 +33,17 @@ public class TimeSeriesDataCachedRepository<TEntity, TDto> : TimeSeriesDataRepos
}).Wait();
}
public override async Task<IEnumerable<TDto>> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
public override async Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset dateBegin, CancellationToken token)
{
if (LastData.Count() == 0 || LastData[0].Date > dateBegin)
{
var dtos = await base.GetAsync(dateBegin, dateEnd, token);
var dtos = await base.GetGtDate(dateBegin, token);
return dtos;
}
var items = LastData
.Where(i => i.Date >= dateBegin && i.Date <= dateEnd);
.Where(i => i.Date >= dateBegin);
return items;
}
@ -64,5 +62,20 @@ public class TimeSeriesDataCachedRepository<TEntity, TDto> : TimeSeriesDataRepos
return result;
}
public override async Task<DatesRangeDto?> GetDatesRange(CancellationToken token)
{
if (FirstByDate == null)
return null;
return await Task.Run(() =>
{
return new DatesRangeDto
{
From = FirstByDate.Date,
To = LastData[^1].Date
};
});
}
}

View File

@ -18,16 +18,7 @@ public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository
protected virtual IQueryable<TEntity> GetQueryReadOnly() => this.db.Set<TEntity>();
public virtual async Task<IEnumerable<TDto>> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
{
var query = GetQueryReadOnly();
var entities = await query.ToArrayAsync(token);
var dtos = entities.Select(e => e.Adapt<TDto>());
return dtos;
}
public virtual async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
public virtual async Task<DatesRangeDto?> GetDatesRange(CancellationToken token)
{
var query = GetQueryReadOnly();
var minDate = await query.MinAsync(o => o.Date, token);
@ -42,6 +33,13 @@ public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository
public virtual async Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset date, CancellationToken token)
{
//var query = GetQueryReadOnly()
// .Where(q => q.Date >= dateBegin);
//var entities = await query.ToArrayAsync(token);
//var dtos = entities.Select(e => e.Adapt<TDto>());
//return dtos;
var query = this.db.Set<TEntity>().Where(e => e.Date > date);
var entities = await query.ToArrayAsync(token);
@ -60,7 +58,7 @@ public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository
return result;
}
public async Task<IEnumerable<TDto>> GetLastAsync(int takeCount, CancellationToken token)
protected async Task<IEnumerable<TDto>> GetLastAsync(int takeCount, CancellationToken token)
{
var query = GetQueryReadOnly()
.OrderByDescending(e => e.Date)
@ -72,7 +70,7 @@ public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository
return dtos;
}
public async Task<TDto?> GetFirstAsync(CancellationToken token)
protected async Task<TDto?> GetFirstAsync(CancellationToken token)
{
var query = GetQueryReadOnly()
.OrderBy(e => e.Date);
@ -85,4 +83,10 @@ public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository
var dto = entity.Adapt<TDto>();
return dto;
}
public Task<IEnumerable<TDto>> GetResampledData(DateTimeOffset dateBegin, DateTimeOffset dateEnd, int approxPointsCount = 1024)
{
//todo
throw new NotImplementedException();
}
}

View File

@ -31,7 +31,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> AddAsync(TDto dto, CancellationToken token);
Task<ActionResult<int>> Add(TDto dto, CancellationToken token);
/// <summary>
/// Добавить несколько записей
@ -39,7 +39,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> AddRangeAsync(IEnumerable<TDto> dtos, CancellationToken token);
Task<ActionResult<int>> AddRange(IEnumerable<TDto> dtos, CancellationToken token);
/// <summary>
/// Обновить одну запись
@ -47,7 +47,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> UpdateAsync(TDto dto, CancellationToken token);
Task<ActionResult<int>> Update(TDto dto, CancellationToken token);
/// <summary>
/// Обновить несколько записей
@ -55,7 +55,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> UpdateRangeAsync(IEnumerable<TDto> dtos, CancellationToken token);
Task<ActionResult<int>> UpdateRange(IEnumerable<TDto> dtos, CancellationToken token);
/// <summary>
/// Удалить одну запись
@ -63,7 +63,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="id"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> DeleteAsync(int id, CancellationToken token);
Task<ActionResult<int>> Delete(int id, CancellationToken token);
/// <summary>
/// Удалить несколько записей
@ -71,5 +71,5 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="ids"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token);
Task<ActionResult<int>> DeleteRange(IEnumerable<int> ids, CancellationToken token);
}

View File

@ -13,7 +13,7 @@ public interface IDictionaryElementApi<TDto> where TDto : class, new()
/// <param name="dictionaryKey">ключ справочника</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<TDto>>> GetAsync(Guid dictionaryKey, CancellationToken token);
Task<ActionResult<IEnumerable<TDto>>> Get(Guid dictionaryKey, CancellationToken token);
/// <summary>
/// Добавить элемент в справочник
@ -22,7 +22,7 @@ public interface IDictionaryElementApi<TDto> where TDto : class, new()
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<Guid>> AddAsync(Guid dictionaryKey, TDto dto, CancellationToken token);
Task<ActionResult<Guid>> Add(Guid dictionaryKey, TDto dto, CancellationToken token);
/// <summary>
/// Изменить одну запись
@ -32,7 +32,7 @@ public interface IDictionaryElementApi<TDto> where TDto : class, new()
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<Guid>> UpdateAsync(Guid dictionaryKey, Guid dictionaryElementKey, TDto dto, CancellationToken token);
Task<ActionResult<Guid>> Update(Guid dictionaryKey, Guid dictionaryElementKey, TDto dto, CancellationToken token);
/// <summary>
/// Удалить одну запись
@ -41,5 +41,5 @@ public interface IDictionaryElementApi<TDto> where TDto : class, new()
/// <param name="dictionaryElementKey">ключ элемента в справочнике</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> DeleteAsync(Guid dictionaryKey, Guid dictionaryElementKey, CancellationToken token);
Task<ActionResult<int>> Delete(Guid dictionaryKey, Guid dictionaryElementKey, CancellationToken token);
}

View File

@ -14,7 +14,7 @@ public interface ISetpointApi
/// <param name="setpoitKeys">ключи уставок</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<SetpointValueDto>>> GetCurrentAsync(IEnumerable<Guid> setpoitKeys, CancellationToken token);
Task<ActionResult<IEnumerable<SetpointValueDto>>> GetCurrent(IEnumerable<Guid> setpoitKeys, CancellationToken token);
/// <summary>
/// Получить значения уставок за определенный момент времени
@ -23,7 +23,7 @@ public interface ISetpointApi
/// <param name="historyMoment">дата, на которую получаем данные</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<SetpointValueDto>>> GetHistoryAsync(IEnumerable<Guid> setpoitKeys, DateTimeOffset historyMoment, CancellationToken token);
Task<ActionResult<IEnumerable<SetpointValueDto>>> GetHistory(IEnumerable<Guid> setpoitKeys, DateTimeOffset historyMoment, CancellationToken token);
/// <summary>
/// Получить историю изменений значений уставок
@ -31,7 +31,7 @@ public interface ISetpointApi
/// <param name="setpoitKeys">ключи уставок</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<Dictionary<Guid, IEnumerable<SetpointLogDto>>>> GetLogAsync(IEnumerable<Guid> setpoitKeys, CancellationToken token);
Task<ActionResult<Dictionary<Guid, IEnumerable<SetpointLogDto>>>> GetLog(IEnumerable<Guid> setpoitKeys, CancellationToken token);
/// <summary>
/// Метод сохранения уставки
@ -40,5 +40,5 @@ public interface ISetpointApi
/// <param name="newValue">значение</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> SaveAsync(Guid setpointKey, object newValue, CancellationToken token);
Task<ActionResult<int>> Save(Guid setpointKey, object newValue, CancellationToken token);
}

View File

@ -15,7 +15,7 @@ public interface ISyncApi<TDto> where TDto : class, new()
/// <param name="take">количество записей</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<TDto>>> GetPartAsync(DateTimeOffset dateBegin, int take = 24 * 60 * 60, CancellationToken token = default);
Task<ActionResult<IEnumerable<TDto>>> GetPart(DateTimeOffset dateBegin, int take = 24 * 60 * 60, CancellationToken token = default);
/// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории

View File

@ -19,5 +19,5 @@ public interface ITableDataApi<TDto, TRequest>
/// <param name="request">параметры фильтрации</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<PaginationContainer<TDto>>> GetPageAsync(TRequest request, CancellationToken token);
Task<ActionResult<PaginationContainer<TDto>>> GetPage(TRequest request, CancellationToken token);
}

View File

@ -4,23 +4,23 @@ using Persistence.Models;
namespace Persistence.API;
/// <summary>
/// Интерфейс для работы с API графиков
/// Базовый интерфейс для работы с временными рядами
/// </summary>
public interface IGraphDataApi<TDto>
public interface ITimeSeriesBaseDataApi<TDto>
{
/// <summary>
/// Получить список объектов с прореживанием, удовлетворящий диапазону дат
/// Получить список объектов с прореживанием, удовлетворяющий диапазону дат
/// </summary>
/// <param name="dateBegin">дата начала</param>
/// <param name="dateEnd">дата окончания</param>
/// <param name="approxPointsCount"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<TDto>>> GetThinnedDataAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, int approxPointsCount = 1024);
Task<IActionResult> GetResampledData(DateTimeOffset dateBegin, DateTimeOffset dateEnd, int approxPointsCount = 1024);
/// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<DatesRangeDto>> GetDatesRangeAsync(CancellationToken token);
Task<IActionResult> GetDatesRange(CancellationToken token);
}

View File

@ -11,24 +11,16 @@ namespace Persistence.API;
/// <summary>
/// Интерфейс для работы с API временных данных
/// </summary>
public interface ITimeSeriesDataApi<TDto>
public interface ITimeSeriesDataApi<TDto> : ITimeSeriesBaseDataApi<TDto>
where TDto : class, ITimeSeriesAbstractDto, new()
{
/// <summary>
/// Получить список объектов, удовлетворяющий диапазон дат
/// </summary>
/// <param name="dateBegin">дата начала</param>
/// <param name="dateEnd">дата окончания</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IActionResult> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token);
/// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task<IActionResult> GetDatesRangeAsync(CancellationToken token);
Task<IActionResult> Get(DateTimeOffset dateBegin, CancellationToken token);
/// <summary>
/// Добавление записей
@ -36,7 +28,7 @@ public interface ITimeSeriesDataApi<TDto>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IActionResult> InsertRangeAsync(IEnumerable<TDto> dtos, CancellationToken token);
Task<IActionResult> InsertRange(IEnumerable<TDto> dtos, CancellationToken token);
}

View File

@ -26,7 +26,7 @@ public class ChangeLogDto<T> where T: class
public DateTimeOffset Creation { get; set; }
/// <summary>
/// Дата устаревания (например при удалении)
/// Дата устаревания (например, при удалении)
/// </summary>
public DateTimeOffset? Obsolete { get; set; }

View File

@ -15,7 +15,7 @@ public interface ISetpointRepository
/// <param name="historyMoment">дата, на которую получаем данные</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<SetpointValueDto>> GetHistoryAsync(IEnumerable<Guid> setpoitKeys, DateTimeOffset historyMoment, CancellationToken token);
Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpoitKeys, DateTimeOffset historyMoment, CancellationToken token);
/// <summary>
/// Получить историю изменений значений уставок
@ -23,7 +23,7 @@ public interface ISetpointRepository
/// <param name="setpoitKeys"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLogAsync(IEnumerable<Guid> setpoitKeys, CancellationToken token);
Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLog(IEnumerable<Guid> setpoitKeys, CancellationToken token);
/// <summary>
/// Метод сохранения уставки
@ -35,5 +35,5 @@ public interface ISetpointRepository
/// <returns></returns>
/// to do
/// id User учесть в соответствующем методе репозитория
Task<int> SaveAsync(Guid setpointKey, int idUser, object newValue, CancellationToken token);
Task<int> Save(Guid setpointKey, int idUser, object newValue, CancellationToken token);
}

View File

@ -15,5 +15,5 @@ public interface ITableDataRepository<TDto, TRequest>
/// <param name="request">параметры фильтрации</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TDto>> GetAsync(TRequest request, CancellationToken token);
Task<IEnumerable<TDto>> Get(TRequest request, CancellationToken token);
}

View File

@ -5,7 +5,7 @@ namespace Persistence.Repositories;
/// <summary>
/// Интерфейс по работе с прореженными данными
/// </summary>
public interface IGraphDataRepository<TDto>
public interface ITimeSeriesBaseRepository<TDto>
where TDto : class, new()
{
/// <summary>
@ -15,12 +15,12 @@ public interface IGraphDataRepository<TDto>
/// <param name="dateEnd">дата окончания</param>
/// <param name="approxPointsCount"></param>
/// <returns></returns>
Task<IEnumerable<TDto>> GetThinnedDataAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, int approxPointsCount = 1024);
Task<IEnumerable<TDto>> GetResampledData(DateTimeOffset dateBegin, DateTimeOffset dateEnd, int approxPointsCount = 1024);
/// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
Task<DatesRangeDto?> GetDatesRange(CancellationToken token);
}

View File

@ -6,24 +6,9 @@ namespace Persistence.Repositories;
/// Интерфейс по работе с временными данными
/// </summary>
/// <typeparam name="TDto"></typeparam>
public interface ITimeSeriesDataRepository<TDto> : ISyncRepository<TDto>
public interface ITimeSeriesDataRepository<TDto> : ISyncRepository<TDto>, ITimeSeriesBaseRepository<TDto>
where TDto : class, ITimeSeriesAbstractDto, new()
{
/// <summary>
/// Получить страницу списка объектов
/// </summary>
/// <param name="dateBegin">дата начала</param>
/// <param name="dateEnd">дата окончания</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TDto>> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token);
/// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
/// <summary>
/// Добавление записей
/// </summary>
@ -31,19 +16,4 @@ public interface ITimeSeriesDataRepository<TDto> : ISyncRepository<TDto>
/// <param name="token"></param>
/// <returns></returns>
Task<int> InsertRange(IEnumerable<TDto> dtos, CancellationToken token);
/// <summary>
/// Получение списка последних записей
/// </summary>
/// <param name="takeCount">количество записей</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TDto>> GetLastAsync(int takeCount, CancellationToken token);
/// <summary>
/// Получение первой записи
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task<TDto?> GetFirstAsync(CancellationToken token);
}