From de2a7cfe04a400f308cc2af0ba9b5ece4d79c1ab Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Wed, 11 Dec 2024 09:30:35 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=B8=D1=81=D0=BA=D1=80=D0=B8=D0=BC=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=20=D0=BA=20=D1=82=D0=B8=D0=BF=D1=83=20int=20=D0=B2=20Cha?= =?UTF-8?q?ngeLog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ChangeLogController.cs | 18 ++++----- .../Clients/IChangeLogClient.cs | 12 +++--- Persistence.Database/Entity/ChangeLog.cs | 2 +- Persistence.Database/Entity/IChangeLog.cs | 2 +- Persistence.Database/PersistenceDbContext.cs | 6 ++- .../Controllers/ChangeLogControllerTest.cs | 39 ++++++++++++------- .../Repositories/ChangeLogRepository.cs | 20 +++++----- Persistence/API/IChangeLogApi.cs | 14 +++---- .../Repositories/IChangeLogRepository.cs | 12 +++--- .../ISyncWithDiscriminatorRepository.cs | 4 +- 10 files changed, 71 insertions(+), 58 deletions(-) diff --git a/Persistence.API/Controllers/ChangeLogController.cs b/Persistence.API/Controllers/ChangeLogController.cs index cad59c4..83a7fb6 100644 --- a/Persistence.API/Controllers/ChangeLogController.cs +++ b/Persistence.API/Controllers/ChangeLogController.cs @@ -22,7 +22,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpPost("{idDiscriminator}")] [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)] public async Task Add( - [FromRoute] Guid idDiscriminator, + [FromRoute] int idDiscriminator, [FromBody] DataWithWellDepthAndSectionDto dto, CancellationToken token) { @@ -35,7 +35,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpPost("range/{idDiscriminator}")] [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)] public async Task AddRange( - [FromRoute] Guid idDiscriminator, + [FromRoute] int idDiscriminator, [FromBody] IEnumerable dtos, CancellationToken token) { @@ -68,7 +68,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpPost("replace/{idDiscriminator}")] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] public async Task ClearAndAddRange( - [FromRoute] Guid idDiscriminator, + [FromRoute] int idDiscriminator, [FromBody] IEnumerable dtos, CancellationToken token) { @@ -104,7 +104,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("{idDiscriminator}")] [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] public async Task GetCurrent( - [FromRoute] Guid idDiscriminator, + [FromRoute] int idDiscriminator, [FromQuery] SectionPartRequest filterRequest, [FromQuery] PaginationRequest paginationRequest, CancellationToken token) @@ -118,7 +118,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("moment/{idDiscriminator}")] [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] public async Task GetByDate( - [FromRoute] Guid idDiscriminator, + [FromRoute] int idDiscriminator, DateTimeOffset moment, [FromQuery] SectionPartRequest filterRequest, [FromQuery] PaginationRequest paginationRequest, @@ -133,7 +133,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] public async Task GetChangeLogForDate( - [FromRoute] Guid idDiscriminator, + [FromRoute] int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token) @@ -146,7 +146,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("datesChange/{idDiscriminator}")] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - public async Task GetDatesChange([FromRoute] Guid idDiscriminator, CancellationToken token) + public async Task GetDatesChange([FromRoute] int idDiscriminator, CancellationToken token) { var result = await repository.GetDatesChange(idDiscriminator, token); @@ -156,7 +156,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("part/{idDiscriminator}")] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - public async Task GetPart([FromRoute] Guid idDiscriminator, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default) + public async Task>> GetPart([FromRoute] int idDiscriminator, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default) { var result = await repository.GetGtDate(idDiscriminator, dateBegin, token); @@ -166,7 +166,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("datesRange/{idDiscriminator}")] [ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - public async Task GetDatesRangeAsync([FromRoute] Guid idDiscriminator, CancellationToken token) + public async Task> GetDatesRangeAsync([FromRoute] int idDiscriminator, CancellationToken token) { var result = await repository.GetDatesRange(idDiscriminator, token); diff --git a/Persistence.Client/Clients/IChangeLogClient.cs b/Persistence.Client/Clients/IChangeLogClient.cs index 06bbc4d..3bb9832 100644 --- a/Persistence.Client/Clients/IChangeLogClient.cs +++ b/Persistence.Client/Clients/IChangeLogClient.cs @@ -18,7 +18,7 @@ public interface IChangeLogClient /// /// [Post($"{BaseRoute}/replace/{{idDiscriminator}}")] - Task> ClearAndAddRange(Guid idDiscriminator, IEnumerable dtos); + Task> ClearAndAddRange(int idDiscriminator, IEnumerable dtos); /// /// Получение актуальных данных на определенную дату (с пагинацией) @@ -30,7 +30,7 @@ public interface IChangeLogClient /// [Get($"{BaseRoute}/moment/{{idDiscriminator}}")] Task>> GetByDate( - Guid idDiscriminator, + int idDiscriminator, DateTimeOffset moment, [Query] SectionPartRequest filterRequest, [Query] PaginationRequest paginationRequest); @@ -43,7 +43,7 @@ public interface IChangeLogClient /// /// [Get($"{BaseRoute}/history/{{idDiscriminator}}")] - Task>> GetChangeLogForInterval(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd); + Task>> GetChangeLogForInterval(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd); /// /// Добавить одну запись @@ -52,7 +52,7 @@ public interface IChangeLogClient /// /// [Post($"{BaseRoute}/{{idDiscriminator}}")] - Task> Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto); + Task> Add(int idDiscriminator, DataWithWellDepthAndSectionDto dto); /// /// Добавить несколько записей @@ -61,7 +61,7 @@ public interface IChangeLogClient /// /// [Post($"{BaseRoute}/range/{{idDiscriminator}}")] - Task> AddRange(Guid idDiscriminator, IEnumerable dtos); + Task> AddRange(int idDiscriminator, IEnumerable dtos); /// /// Обновить одну запись @@ -101,6 +101,6 @@ public interface IChangeLogClient /// /// [Get($"{BaseRoute}/datesRange/{{idDiscriminator}}")] - Task> GetDatesRange(Guid idDiscriminator); + Task> GetDatesRange(int idDiscriminator); } diff --git a/Persistence.Database/Entity/ChangeLog.cs b/Persistence.Database/Entity/ChangeLog.cs index 9a8001b..eb921aa 100644 --- a/Persistence.Database/Entity/ChangeLog.cs +++ b/Persistence.Database/Entity/ChangeLog.cs @@ -15,7 +15,7 @@ public class ChangeLog : IChangeLog, IWithSectionPart public Guid Id { get; set; } [Comment("Дискриминатор таблицы")] - public Guid IdDiscriminator { get; set; } + public int IdDiscriminator { get; set; } [Comment("Автор изменения")] public Guid IdAuthor { get; set; } diff --git a/Persistence.Database/Entity/IChangeLog.cs b/Persistence.Database/Entity/IChangeLog.cs index c4dc962..b68bb0b 100644 --- a/Persistence.Database/Entity/IChangeLog.cs +++ b/Persistence.Database/Entity/IChangeLog.cs @@ -39,7 +39,7 @@ public interface IChangeLog /// /// Дискриминатор таблицы /// - public Guid IdDiscriminator { get; set; } + public int IdDiscriminator { get; set; } /// /// Значение diff --git a/Persistence.Database/PersistenceDbContext.cs b/Persistence.Database/PersistenceDbContext.cs index 4393ac1..849865d 100644 --- a/Persistence.Database/PersistenceDbContext.cs +++ b/Persistence.Database/PersistenceDbContext.cs @@ -17,7 +17,11 @@ public class PersistenceDbContext : DbContext public DbSet ChangeLog => Set(); - public PersistenceDbContext(DbContextOptions options) + public DbSet TechMessage => Set(); + + public DbSet ParameterData => Set(); + + public PersistenceDbContext(DbContextOptions options) : base(options) { diff --git a/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs b/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs index 8c3b422..9641a1e 100644 --- a/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Persistence.Client; using Persistence.Client.Clients; +using Persistence.Database.Entity; using Persistence.Database.Model; using Persistence.Models; using Persistence.Models.Requests; @@ -26,8 +27,10 @@ public class ChangeLogControllerTest : BaseIntegrationTest [Fact] public async Task ClearAndInsertRange_InEmptyDb() { - // arrange - var idDiscriminator = Guid.NewGuid(); + // arrange + dbContext.CleanupDbSet(); + + var idDiscriminator = 1; var dtos = Generate(2, DateTimeOffset.UtcNow); // act @@ -60,7 +63,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest { // arrange var count = 1; - var idDiscriminator = Guid.NewGuid(); + var idDiscriminator = 1; var dtos = Generate(count, DateTimeOffset.UtcNow); var dto = dtos.FirstOrDefault()!; @@ -77,7 +80,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest { // arrange var count = 3; - var idDiscriminator = Guid.NewGuid(); + var idDiscriminator = 1; var dtos = Generate(count, DateTimeOffset.UtcNow); // act @@ -91,8 +94,10 @@ public class ChangeLogControllerTest : BaseIntegrationTest [Fact] public async Task Update_returns_success() { - // arrange - var idDiscriminator = Guid.NewGuid(); + // arrange + dbContext.CleanupDbSet(); + + var idDiscriminator = 1; var dtos = Generate(1, DateTimeOffset.UtcNow); var dto = dtos.FirstOrDefault()!; var result = await client.Add(idDiscriminator, dto); @@ -232,9 +237,11 @@ public class ChangeLogControllerTest : BaseIntegrationTest [Fact] public async Task GetByDate_returns_success() { - // arrange - //создаем записи - var count = 5; + // arrange + dbContext.CleanupDbSet(); + + //создаем записи + var count = 5; var changeLogItems = CreateChangeLogItems(count, (-15, 15)); var idDiscriminator = changeLogItems.Item1; var entities = changeLogItems.Item2; @@ -284,12 +291,14 @@ public class ChangeLogControllerTest : BaseIntegrationTest int daysAfterNowFilter, int changeLogCount) { - // arrange - //создаем записи - var count = insertedCount; + // arrange + dbContext.CleanupDbSet(); + + //создаем записи + var count = insertedCount; var daysRange = (daysBeforeNowChangeLog, daysAfterNowChangeLog); var changeLogItems = CreateChangeLogItems(count, daysRange); - var idDiscriminator = changeLogItems.Item1; + var idDiscriminator = 1; var entities = changeLogItems.Item2; foreach (var entity in entities) @@ -328,12 +337,12 @@ public class ChangeLogControllerTest : BaseIntegrationTest } - private (Guid, ChangeLog[]) CreateChangeLogItems(int count, (int, int) daysRange) + private (int, ChangeLog[]) CreateChangeLogItems(int count, (int, int) daysRange) { var minDayCount = daysRange.Item1; var maxDayCount = daysRange.Item2; - Guid idDiscriminator = Guid.NewGuid(); + var idDiscriminator = 1; var dtos = Generate(count, DateTimeOffset.UtcNow); var entities = dtos.Select(d => { diff --git a/Persistence.Repository/Repositories/ChangeLogRepository.cs b/Persistence.Repository/Repositories/ChangeLogRepository.cs index ac00e05..0291c1b 100644 --- a/Persistence.Repository/Repositories/ChangeLogRepository.cs +++ b/Persistence.Repository/Repositories/ChangeLogRepository.cs @@ -16,7 +16,7 @@ public class ChangeLogRepository : IChangeLogRepository this.db = db; } - public async Task AddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token) + public async Task AddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token) { var entities = new List(); foreach (var dto in dtos) @@ -49,7 +49,7 @@ public class ChangeLogRepository : IChangeLogRepository return result; } - public async Task MarkAsDeleted(Guid idEditor, Guid idDiscriminator, CancellationToken token) + public async Task MarkAsDeleted(Guid idEditor, int idDiscriminator, CancellationToken token) { var query = db.Set() .Where(s => s.IdDiscriminator == idDiscriminator) @@ -75,7 +75,7 @@ public class ChangeLogRepository : IChangeLogRepository return await db.SaveChangesAsync(token); } - public async Task ClearAndAddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token) + public async Task ClearAndAddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token) { var result = 0; @@ -127,7 +127,7 @@ public class ChangeLogRepository : IChangeLogRepository } public async Task> GetByDate( - Guid idDiscriminator, + int idDiscriminator, DateTimeOffset momentUtc, SectionPartRequest filterRequest, PaginationRequest paginationRequest, @@ -142,14 +142,14 @@ public class ChangeLogRepository : IChangeLogRepository return result; } - private IQueryable CreateQuery(Guid idDiscriminator) + private IQueryable CreateQuery(int idDiscriminator) { var query = db.Set().Where(e => e.IdDiscriminator == idDiscriminator); return query; } - public async Task> GetChangeLogForInterval(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token) + public async Task> GetChangeLogForInterval(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token) { var query = db.Set().Where(s => s.IdDiscriminator == idDiscriminator); @@ -169,7 +169,7 @@ public class ChangeLogRepository : IChangeLogRepository - public async Task> GetDatesChange(Guid idDiscriminator, CancellationToken token) + public async Task> GetDatesChange(int idDiscriminator, CancellationToken token) { var query = db.Set().Where(e => e.IdDiscriminator == idDiscriminator); @@ -195,7 +195,7 @@ public class ChangeLogRepository : IChangeLogRepository return datesOnly; } - private ChangeLog CreateEntityFromDto(Guid idAuthor, Guid idDiscriminator, DataWithWellDepthAndSectionDto dto) + private ChangeLog CreateEntityFromDto(Guid idAuthor, int idDiscriminator, DataWithWellDepthAndSectionDto dto) { var entity = new ChangeLog() { @@ -214,7 +214,7 @@ public class ChangeLogRepository : IChangeLogRepository return entity; } - public async Task> GetGtDate(Guid idDiscriminator, DateTimeOffset dateBegin, CancellationToken token) + public async Task> GetGtDate(int idDiscriminator, DateTimeOffset dateBegin, CancellationToken token) { var date = dateBegin.ToUniversalTime(); var query = this.db.Set() @@ -228,7 +228,7 @@ public class ChangeLogRepository : IChangeLogRepository return dtos; } - public async Task GetDatesRange(Guid idDiscriminator, CancellationToken token) + public async Task GetDatesRange(int idDiscriminator, CancellationToken token) { var query = db.Set() .Where(e => e.IdDiscriminator == idDiscriminator) diff --git a/Persistence/API/IChangeLogApi.cs b/Persistence/API/IChangeLogApi.cs index 25b5158..cbf2127 100644 --- a/Persistence/API/IChangeLogApi.cs +++ b/Persistence/API/IChangeLogApi.cs @@ -16,7 +16,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task ClearAndAddRange(Guid idDiscriminator, IEnumerable dtos, CancellationToken token); + Task ClearAndAddRange(int idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Получение данных на текущую дату (с пагинацией) @@ -26,7 +26,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApiпараметры запроса пагинации /// /// - Task GetCurrent(Guid idDiscriminator, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); + Task GetCurrent(int idDiscriminator, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); /// /// Получение данных на определенную дату (с пагинацией) @@ -37,7 +37,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApiпараметры запроса пагинации /// /// - Task GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); + Task GetByDate(int idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); /// /// Получение исторических данных за определенный период времени @@ -47,7 +47,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); + Task GetChangeLogForDate(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); /// /// Добавить одну запись @@ -56,7 +56,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token); + Task Add(int idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token); /// /// Добавить несколько записей @@ -65,7 +65,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task AddRange(Guid idDiscriminator, IEnumerable dtos, CancellationToken token); + Task AddRange(int idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Обновить одну запись @@ -105,5 +105,5 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task GetDatesChange(Guid idDiscriminator, CancellationToken token); + Task GetDatesChange(int idDiscriminator, CancellationToken token); } diff --git a/Persistence/Repositories/IChangeLogRepository.cs b/Persistence/Repositories/IChangeLogRepository.cs index e197090..3db37b6 100644 --- a/Persistence/Repositories/IChangeLogRepository.cs +++ b/Persistence/Repositories/IChangeLogRepository.cs @@ -17,7 +17,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task AddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token); + Task AddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Пометить записи как удаленные @@ -35,7 +35,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepositoryдискриминатор таблицы /// /// - Task MarkAsDeleted(Guid idEditor, Guid idDiscriminator, CancellationToken token); + Task MarkAsDeleted(Guid idEditor, int idDiscriminator, CancellationToken token); /// /// Очистить и добавить новые @@ -45,7 +45,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task ClearAndAddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token); + Task ClearAndAddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Редактирование записей @@ -65,7 +65,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepositoryпараметры запроса пагинации /// /// - Task> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); + Task> GetByDate(int idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); /// /// Получение измененных записей за период времени @@ -75,7 +75,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task> GetChangeLogForInterval(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); + Task> GetChangeLogForInterval(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); /// /// Получение списка дат, в которые происходили изменения (день, месяц, год, без времени) @@ -83,5 +83,5 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task> GetDatesChange(Guid idDiscriminator, CancellationToken token); + Task> GetDatesChange(int idDiscriminator, CancellationToken token); } diff --git a/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs b/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs index 7e0bd62..af8c807 100644 --- a/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs +++ b/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs @@ -15,7 +15,7 @@ public interface ISyncWithDiscriminatorRepository /// дата начала /// /// /// - Task> GetGtDate(Guid idDiscriminator, DateTimeOffset dateBegin, CancellationToken token); + Task> GetGtDate(int idDiscriminator, DateTimeOffset dateBegin, CancellationToken token); /// @@ -24,5 +24,5 @@ public interface ISyncWithDiscriminatorRepository /// дискриминатор таблицы /// /// - Task GetDatesRange(Guid idDiscriminator, CancellationToken token); + Task GetDatesRange(int idDiscriminator, CancellationToken token); }