From c54e9cb35c25c8f72f049ad17929e437be7eefac Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 29 Nov 2024 11:52:47 +0500 Subject: [PATCH] =?UTF-8?q?ISyncWithDiscriminatorApi=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B5=D0=B9,=20?= =?UTF-8?q?=D1=83=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B4=D0=B8=D1=81=D0=BA=D1=80=D0=B8=D0=BC?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D1=82=D0=BE=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ChangeLogController.cs | 15 +++++++++- .../Repositories/ChangeLogRepository.cs | 26 +++++++++++++++++ Persistence/API/IChangeLogApi.cs | 2 +- Persistence/API/ISyncApi.cs | 2 +- Persistence/API/ISyncWithDiscriminatorApi.cs | 28 +++++++++++++++++++ .../Repositories/IChangeLogRepository.cs | 2 +- Persistence/Repositories/ISyncRepository.cs | 14 ++++++++-- .../ISyncWithDiscriminatorRepository.cs | 28 +++++++++++++++++++ .../Repositories/ITimeSeriesBaseRepository.cs | 7 ----- 9 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 Persistence/API/ISyncWithDiscriminatorApi.cs create mode 100644 Persistence/Repositories/ISyncWithDiscriminatorRepository.cs diff --git a/Persistence.API/Controllers/ChangeLogController.cs b/Persistence.API/Controllers/ChangeLogController.cs index 08f059e..f65cbb1 100644 --- a/Persistence.API/Controllers/ChangeLogController.cs +++ b/Persistence.API/Controllers/ChangeLogController.cs @@ -146,8 +146,21 @@ public class ChangeLogController : ControllerBase, IChangeLogApi return Ok(result); } + [HttpGet("part")] + [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] + public async Task GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default) + { + var result = await repository.GetGtDate(idDiscriminator, dateBegin, token); + return Ok(result); + } + [HttpGet("datesRange")] + [ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)] + public async Task GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token) + { + var result = await repository.GetDatesRange(idDiscriminator, token); - + return Ok(result); + } } diff --git a/Persistence.Repository/Repositories/ChangeLogRepository.cs b/Persistence.Repository/Repositories/ChangeLogRepository.cs index 5bfb870..98ff7d3 100644 --- a/Persistence.Repository/Repositories/ChangeLogRepository.cs +++ b/Persistence.Repository/Repositories/ChangeLogRepository.cs @@ -256,4 +256,30 @@ public class ChangeLogRepository : IChangeLogRepository return entity; } + public async Task> GetGtDate(Guid idDiscriminator, DateTimeOffset dateBegin, CancellationToken token) + { + var date = dateBegin.ToUniversalTime(); + var query = this.db.Set() + .Where(e => e.IdDiscriminator == idDiscriminator) + .Where(e => e.Creation >= date || e.Obsolete >= date); + + var entities = await query.ToArrayAsync(token); + + var dtos = entities.Select(e => e.Adapt()); + + return dtos; + } + + public async Task GetDatesRange(Guid idDiscriminator, CancellationToken token) + { + var query = this.db.Set().Where(e => e.IdDiscriminator == idDiscriminator); + var minDate = await query.MinAsync(o => o.Creation, token); + var maxDate = await query.MaxAsync(o => o.Creation, token); + + return new DatesRangeDto + { + From = minDate, + To = maxDate + }; + } } diff --git a/Persistence/API/IChangeLogApi.cs b/Persistence/API/IChangeLogApi.cs index a46fc98..40ca8ae 100644 --- a/Persistence/API/IChangeLogApi.cs +++ b/Persistence/API/IChangeLogApi.cs @@ -7,7 +7,7 @@ namespace Persistence.API; /// /// Интерфейс для работы с API журнала изменений /// -public interface IChangeLogApi +public interface IChangeLogApi : ISyncWithDiscriminatorApi { /// /// Импорт с заменой: удаление старых строк и добавление новых diff --git a/Persistence/API/ISyncApi.cs b/Persistence/API/ISyncApi.cs index 7f72812..286df3d 100644 --- a/Persistence/API/ISyncApi.cs +++ b/Persistence/API/ISyncApi.cs @@ -6,7 +6,7 @@ namespace Persistence.API; /// /// Интерфейс для API, предназначенного для синхронизации данных /// -public interface ISyncApi where TDto : class, new() +public interface ISyncApi where TDto : class { /// /// Получить порцию записей, начиная с заданной даты diff --git a/Persistence/API/ISyncWithDiscriminatorApi.cs b/Persistence/API/ISyncWithDiscriminatorApi.cs new file mode 100644 index 0000000..c0c72f0 --- /dev/null +++ b/Persistence/API/ISyncWithDiscriminatorApi.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; +using Persistence.Models; + +namespace Persistence.API; + +/// +/// Интерфейс для API, предназначенного для синхронизации данных, у которых есть дискриминатор +/// +public interface ISyncWithDiscriminatorApi +{ + /// + /// Получить порцию записей, начиная с заданной даты + /// + /// + /// + /// количество записей + /// + /// + Task GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take = 24 * 60 * 60, CancellationToken token = default); + + /// + /// Получить диапазон дат, для которых есть данные в репозитории + /// + /// + /// + /// + Task GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token); +} diff --git a/Persistence/Repositories/IChangeLogRepository.cs b/Persistence/Repositories/IChangeLogRepository.cs index b5cd53a..c885c90 100644 --- a/Persistence/Repositories/IChangeLogRepository.cs +++ b/Persistence/Repositories/IChangeLogRepository.cs @@ -7,7 +7,7 @@ namespace Persistence.Repositories; /// Интерфейс для работы с историческими данными /// /// -public interface IChangeLogRepository //: ISyncRepository +public interface IChangeLogRepository : ISyncWithDiscriminatorRepository { /// /// Добавление записей diff --git a/Persistence/Repositories/ISyncRepository.cs b/Persistence/Repositories/ISyncRepository.cs index e18c5f5..5a5c9be 100644 --- a/Persistence/Repositories/ISyncRepository.cs +++ b/Persistence/Repositories/ISyncRepository.cs @@ -1,17 +1,25 @@ -namespace Persistence.Repositories; +using Persistence.Models; + +namespace Persistence.Repositories; /// /// Интерфейс по работе с данными /// /// public interface ISyncRepository - where TDto : class, new() { /// /// Получить данные, начиная с определенной даты /// /// дата начала + /// /// + Task> GetGtDate(DateTimeOffset dateBegin, CancellationToken token); + + + /// + /// Получить диапазон дат, для которых есть данные в репозитории + /// /// /// - Task> GetGtDate(DateTimeOffset dateBegin, CancellationToken token); + Task GetDatesRange(CancellationToken token); } diff --git a/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs b/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs new file mode 100644 index 0000000..7e0bd62 --- /dev/null +++ b/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs @@ -0,0 +1,28 @@ +using Persistence.Models; + +namespace Persistence.Repositories; + +/// +/// Интерфейс по работе с данными, у которых есть дискриминатор +/// +/// +public interface ISyncWithDiscriminatorRepository +{ + /// + /// Получить данные, начиная с определенной даты + /// + /// дискриминатор таблицы + /// дата начала + /// + /// /// + Task> GetGtDate(Guid idDiscriminator, DateTimeOffset dateBegin, CancellationToken token); + + + /// + /// Получить диапазон дат, для которых есть данные в репозитории + /// + /// дискриминатор таблицы + /// + /// + Task GetDatesRange(Guid idDiscriminator, CancellationToken token); +} diff --git a/Persistence/Repositories/ITimeSeriesBaseRepository.cs b/Persistence/Repositories/ITimeSeriesBaseRepository.cs index 7102d97..26edf2f 100644 --- a/Persistence/Repositories/ITimeSeriesBaseRepository.cs +++ b/Persistence/Repositories/ITimeSeriesBaseRepository.cs @@ -19,11 +19,4 @@ public interface ITimeSeriesBaseRepository double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default); - - /// - /// Получить диапазон дат, для которых есть данные в репозитории - /// - /// - /// - Task GetDatesRange(CancellationToken token); }